List of usage examples for org.joda.time.format DateTimeFormatter print
public String print(ReadablePartial partial)
From source file:ch.corten.aha.worldclock.TimeZoneInfo.java
License:Open Source License
public static String formatDate(DateFormat dateFormat, DateTimeZone tz, long time) { if (dateFormat instanceof SimpleDateFormat) { String pattern = ((SimpleDateFormat) dateFormat).toPattern(); DateTimeFormatter format = DateTimeFormat.forPattern(pattern).withZone(tz); return format.print(time); } else {/* ww w . j a v a 2s.com*/ dateFormat.setTimeZone(convertToJavaTimeZone(tz, time)); return dateFormat.format(new Date(time)); } }
From source file:ch.corten.aha.worldclock.TimeZoneInfo.java
License:Open Source License
public static String showDifferentWeekday(DateTimeZone tz, long time) { DateTimeFormatter dayFormat = DateTimeFormat.forPattern(WEEKDAY_FORMAT).withZone(tz); String day = dayFormat.print(time); DateTimeFormatter localDayFormat = DateTimeFormat.forPattern(WEEKDAY_FORMAT); if (!day.equals(localDayFormat.print(time))) { return " " + day; }//from w w w . j a v a 2s .c om return ""; }
From source file:ch.icclab.cyclops.persistence.orm.InstanceORM.java
License:Open Source License
/** * Current time/* w w w . j a v a 2s.co m*/ * @return string */ private String getCurrentTime() { DateTimeFormatter fmt = DateTimeFormat.forPattern("H:m:s.S d/MMM/y"); return fmt.print(new DateTime()); }
From source file:ch.qos.logback.classic.issue.lbclassic36.DateFormatPerf_Tapp.java
License:Open Source License
static double doRawJoda() { DateTimeFormatter jodaFormat = DateTimeFormat.forPattern(ISO8601_PATTERN); long timeInMillis = new Date().getTime(); long start = System.nanoTime(); for (int i = 0; i < RUN_LENGTH; ++i) { jodaFormat.print(timeInMillis); }//from ww w . j a v a2 s .co m return (System.nanoTime() - start) * 1.0d / RUN_LENGTH; }
From source file:com.addthis.hydra.data.util.DateUtil.java
License:Apache License
public static String format(DateTimeFormatter formatter, long time) { return formatter.print(time); }
From source file:com.anrisoftware.simplerest.oanda.rest.AbstractInstrumentHistory.java
License:Open Source License
private String toRfc3339Date(DateTime date) { DateTime dt = new DateTime(date, DateTimeZone.UTC); DateTimeFormatter fmt = ISODateTimeFormat.dateTime(); return fmt.print(dt); }
From source file:com.apm4all.tracy.RouteBuilder.java
License:Apache License
@Override public void configure() throws Exception { Tracer tracer = new Tracer(); tracer.setTraceOutExchanges(true);/*from ww w . ja va2 s .com*/ tracer.setEnabled(false); // we configure the default trace formatter where we can // specify which fields we want in the output DefaultTraceFormatter formatter = new DefaultTraceFormatter(); // formatter.setShowOutBody(true); // formatter.setShowOutBodyType(true); formatter.setShowBody(true); formatter.setShowBodyType(true); // set to use our formatter tracer.setFormatter(formatter); getContext().addInterceptStrategy(tracer); // configure we want to use servlet as the component for the rest DSL // and we enable json binding mode //netty4-http restConfiguration().component("servlet").bindingMode(RestBindingMode.json) // and output using pretty print .dataFormatProperty("prettyPrint", "true") // setup context path and port number that netty will use .contextPath("tws").port(8080) // add swagger api-doc out of the box .apiContextPath("/api-doc").apiProperty("api.title", "Tracy Web Services API") .apiProperty("api.version", "1.0.0") // and enable CORS .apiProperty("cors", "true"); rest().description("Tracy Web Service").consumes("application/json").produces("application/json") .get("/applications/{application}/tasks/{task}/measurement") .description("Get measurement for a Task").outType(TaskMeasurement.class).param() .name("application").type(path).description("The application to measure").dataType("string") .endParam().param().name("task").type(path).description("The task to measure").dataType("string") .endParam().to("direct:taskMeasurement") .get("/applications/{application}/measurement").description("Get measurement for an Application") .outType(ApplicationMeasurement.class).param().name("application").type(path) .description("The application to measure").dataType("string").endParam() .to("bean:applicationMeasurementService?method=getApplicationMeasurement(${header.application})") .post("/applications/{application}/tasks/{task}/config").description("Set Task config") .type(TaskConfig.class).param().name("application").type(path).description("The application") .dataType("string").endParam().param().name("task").type(path).description("The task") .dataType("string").endParam().to("bean:esTaskConfig?method=setTaskConfig") .get("/applications/{application}/tasks/{task}/config").description("Get Task config") .outType(TaskConfig.class).param().name("application").type(path).description("The application") .dataType("string").endParam().param().name("task").type(path).description("The task") .dataType("string").endParam().to("bean:esTaskConfig?method=getTaskConfig") .options("/applications/{application}/tasks/{task}/config").to("direct:trash") .get("/registry").description("Get Tracy Registry containing supported environments") .to("direct:registry") .get("/capabilities") .description("Get Server capabilities (Applications/Tasks supported and associated views)") .to("direct:capabilities") .get("/applications/{application}/tasks/{task}/analysis").description("Get analysis for a Task") .outType(TaskAnalysisFake.class).param().name("application").type(path) .description("The application to analyse").dataType("string").endParam().param().name("task") .type(path).description("The task to analyse").dataType("string").endParam().param() .name("earliest").type(query).description("The earliest time (in epoch msec)").dataType("integer") .endParam().param().name("latest").type(query).description("The latest time (in epoch msec)") .dataType("integer").endParam().param().name("filter").type(query) .description("The expression to filter analysis").dataType("string").endParam().param().name("sort") .type(query).description("The fields to sort by").dataType("string").endParam().param() .name("limit").type(query).defaultValue("20") .description("The number of records to analyse, i.e. page size, default is 20").dataType("integer") .endParam().param().name("offset").type(query).description("The page number").defaultValue("1") .dataType("integer").endParam().to("direct:taskAnalysis") .delete("/tracy").description("Delete all Tracy events stored in backed") .to("direct:flushTracyRequest") .post("/tracySimulation").description("Produce Tracy for simulation purposes") .to("direct:toogleTracySimulation") .get("/demo").to("direct:getSimulation") .post("/demo").to("direct:setSimulation"); from("direct:trash").stop(); from("direct:getSimulation").routeId("getSimulation").setBody(simple("")).process(new Processor() { @Override public void process(Exchange exchange) throws Exception { Map<String, Boolean> state = new HashMap<String, Boolean>(); state.put("demo", tracySimulationEnabled); exchange.getIn().setBody(state); } }); from("direct:setSimulation").routeId("setSimulation") // .log("${body}") .process(new Processor() { @Override public void process(Exchange exchange) throws Exception { Map<String, Boolean> state = (Map<String, Boolean>) exchange.getIn().getBody(); tracySimulationEnabled = state.get("demo"); state.put("demo", tracySimulationEnabled); exchange.getIn().setBody(state); } }); from("direct:toogleTracySimulation").routeId("toogleTracySimulation").setBody(simple("")) .process(new Processor() { @Override public void process(Exchange exchange) throws Exception { String response; tracySimulationEnabled = !tracySimulationEnabled; if (tracySimulationEnabled) { response = "Tracy simulation enabled"; } else { response = "Tracy simulation disabled"; } exchange.getIn().setBody(response); } }); from("quartz://everySecond?cron=0/1+*+*+*+*+?").routeId("everySecondTimer").process(new Processor() { @Override public void process(Exchange exchange) throws Exception { Map<String, Object> headers = exchange.getIn().getHeaders(); if (tracySimulationEnabled) { headers.put(TRACY_SIMULATION_ENABLED, new Boolean(true)); } else { headers.put(TRACY_SIMULATION_ENABLED, new Boolean(false)); } } }).to("seda:flushTracy").choice().when(simple("${in.header.TRACY_SIMULATION_ENABLED} == true")) // .loop(100).to("seda:generateTracy") .to("seda:generateTracy") // To not loop .end(); from("seda:generateTracy").routeId("generateTracy").setBody(simple("")).process(new Processor() { @Override public void process(Exchange exchange) throws Exception { //TODO: Extract Tracy generation to a separate thread final String COMPONENT = "hello-tracy"; final String OUTER = "serviceEndpoint"; final String INNER = "dodgyBackend"; int status = 200; long random = new Double(Math.random() * 100).longValue() + 1; if (random <= 80) { status = 200; } // 80% 200: OK else if (random > 99) { status = 202; } // 1% 202: Accepted else if (random > 97) { status = 429; } // 1% 307: Temp redirect else if (random > 87) { status = 404; } // 10% 404: Not found else if (random > 84) { status = 401; } // 3% 401: Unauthorized else if (random > 82) { status = 400; } // 2% 404: Bad request else if (random > 81) { status = 307; } // 2% 429: Too many requests else if (random > 80) { status = 500; } // 1% 500: Internal server error Tracy.setContext(null, null, COMPONENT); Tracy.before(OUTER); Tracy.annotate("status", status); Tracy.before(INNER); // long delayInMsec = new Double(Math.random() * 2).longValue() + 2; long delayInMsec = new Double(Math.random() * 200).longValue() + 100; Thread.sleep(delayInMsec); Tracy.after(INNER); // delayInMsec = new Double(Math.random() * 2).longValue() + 2; delayInMsec = new Double(Math.random() * 10).longValue() + 10; Thread.sleep(delayInMsec); Tracy.after(OUTER); exchange.getIn().setBody(Tracy.getEventsAsJson()); Tracy.clearContext(); } }).to("seda:ingestTracy"); from("direct:flushTracyRequest").routeId("flushTracyRequest").process(new Processor() { @Override public void process(Exchange exchange) throws Exception { flushTracy = true; } }).setBody(simple("Flushed all Tracy events")).log("Flush request accepted"); from("seda:flushTracy").routeId("flushTracy") // .log("Flush request processing started") .process(new Processor() { @Override public void process(Exchange exchange) throws Exception { Map<String, Object> headers = exchange.getIn().getHeaders(); if (flushTracy) { headers.clear(); headers.put(FLUSH_TRACY, new Boolean(true)); flushTracy = false; } else { headers.clear(); headers.put(FLUSH_TRACY, new Boolean(false)); } exchange.getIn().setBody(""); } }).setHeader(Exchange.HTTP_METHOD, constant(org.apache.camel.component.http4.HttpMethods.DELETE)) // .log("Flush request ready to be sent") .choice().when(simple("${in.header.FLUSH_TRACY} == true")) //TODO: Hanle 404 status (nothing to delete) gracefully .to("http4://localhost:9200/tracy-*/tracy") //TODO: Investigate why Camel ES Delete is not working // .setHeader(ElasticsearchConstants.PARAM_INDEX_NAME, simple("tracy-hello-tracy-*")) // .setHeader(ElasticsearchConstants.PARAM_INDEX_TYPE, simple("tracy")) // .to("elasticsearch://local?operation=DELETE"); .log("Flush request sent").end(); from("seda:ingestTracy").routeId("ingestTracy") //TODO: If tracySegment instead of tracyFrame, split into Tracy frames (not required for MVC) .split(body()) // .setHeader(ElasticsearchConstants.PARAM_INDEX_NAME, "tracy-" + simple("${body[component]}") .process(new Processor() { @Override public void process(Exchange exchange) throws Exception { ObjectMapper m = new ObjectMapper(); JsonNode rootNode = m.readTree((String) exchange.getIn().getBody()); DateTime dt = new DateTime(rootNode.path("msecBefore").asLong(), DateTimeZone.UTC); String esTimestamp = dt.toString("yyyy-MM-dd'T'HH:mm:ss.SSS"); ((ObjectNode) rootNode).put("@timestamp", esTimestamp); StringBuilder index = new StringBuilder(); DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy.MM.dd"); String dateString = fmt.print(dt); index.append("tracy-").append(rootNode.path("component").textValue()).append("-") .append(dateString); exchange.getIn().setHeader(ElasticsearchConstants.PARAM_INDEX_NAME, index.toString()); exchange.getIn().setHeader(ElasticsearchConstants.PARAM_INDEX_TYPE, "tracy"); String indexId = rootNode.path("taskId").textValue() + "_" + rootNode.path("optId").textValue(); exchange.getIn().setHeader(ElasticsearchConstants.PARAM_INDEX_ID, indexId); exchange.getIn().setBody(m.writer().writeValueAsString(rootNode)); } }) // .log("${body}") // .log("${headers}") .to("elasticsearch://local?operation=INDEX"); from("direct:registry").routeId("registry").process(new Processor() { @Override public void process(Exchange exchange) throws Exception { ObjectMapper m = new ObjectMapper(); Map<String, Object> registry = m.readValue( "{\"environments\":[{\"name\":\"Local1\",\"servers\":[{\"url\":\"http://localhost:8080/tws/v1\"}]},{\"name\":\"Local2\",\"servers\":[{\"url\":\"http://localhost:8080/tws/v1\"}]}]}", Map.class); exchange.getIn().setBody(registry); } }); from("direct:capabilities").routeId("capabilities").process(new Processor() { @Override public void process(Exchange exchange) throws Exception { ObjectMapper m = new ObjectMapper(); Map<String, Object> capabilities = m.readValue( "{\"capabilities\":{\"applications\":[{\"name\":\"appX\",\"views\":[{\"label\":\"Measurement\",\"name\":\"measurement\"}],\"tasks\":[{\"name\":\"taskX1\",\"views\":[{\"label\":\"Measurement\",\"name\":\"measurement\"}]}]}]}}", Map.class); exchange.getIn().setBody(capabilities); } }); from("direct:taskMeasurement").routeId("taskMeasurement").choice() .when(simple("${in.header.application} contains 'demo-live'")) .bean("esTaskMeasurement", "getTaskMeasurement") .when(simple("${in.header.application} contains 'demo-static'")) .to("bean:taskMeasurementService?method=getTaskMeasurement(${header.application}, ${header.task})") .end(); from("direct:taskAnalysis").routeId("taskAnalysis") // .log("${headers}") .choice().when(simple("${in.header.application} contains 'demo-live'")) .bean("esTaskAnalysis", "getTaskAnalysis") .when(simple("${in.header.application} contains 'demo-static'")) .to("bean:taskAnalysisService?method=getTaskAnalysis" + "(${header.application}, ${header.task}, ${header.earliest}, ${header.latest}, ${header.filter}, ${header.sort}, ${header.limit}, ${header.offset})") .end(); }
From source file:com.atlassian.theplugin.idea.ui.CommentPanel.java
License:Apache License
public CommentPanel(int cmtNumber, final JIRAComment comment, final ServerData server, JTabbedPane tabs, IssueDetailsToolWindow.IssuePanel ip) { setOpaque(true);/* w ww . j av a2 s. c o m*/ setBackground(com.intellij.util.ui.UIUtil.getTextFieldBackground()); int upperMargin = cmtNumber == 1 ? 0 : COMMENT_GAP; setLayout(new GridBagLayout()); GridBagConstraints gbc; JEditorPane commentBody = new JEditorPane(); btnShowHide = new ShowHideButton(commentBody, this); HeaderListener headerListener = new HeaderListener(); gbc = new GridBagConstraints(); gbc.gridx++; gbc.gridy = 0; gbc.anchor = GridBagConstraints.WEST; gbc.insets = new Insets(upperMargin, 0, 0, 0); add(btnShowHide, gbc); gbc.gridx++; gbc.insets = new Insets(upperMargin, Constants.DIALOG_MARGIN / 2, 0, 0); UserLabel ul = new UserLabel(); ul.setUserName(server != null ? server.getUrl() : "", comment.getAuthorFullName(), comment.getAuthor(), false); ul.setFont(ul.getFont().deriveFont(Font.BOLD)); add(ul, gbc); final JLabel hyphen = new WhiteLabel(); hyphen.setText("-"); gbc.gridx++; gbc.insets = new Insets(upperMargin, Constants.DIALOG_MARGIN / 2, 0, Constants.DIALOG_MARGIN / 2); add(hyphen, gbc); final JLabel creationDate = new WhiteLabel(); creationDate.setForeground(Color.GRAY); creationDate.setFont(creationDate.getFont().deriveFont(Font.ITALIC)); // DateFormat df = new SimpleDateFormat("EEE MMM d HH:mm:ss Z yyyy", Locale.US); // DateFormat dfo = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); // DateTimeFormatter dft = DateTimeFormat.forPattern("EEE MMM d HH:mm:ss Z yyyy").withLocale(Locale.US); DateTimeFormatter dfto = DateTimeFormat.shortDateTime().withLocale(Locale.US); String t; // try { t = dfto.print(new DateTime(comment.getCreationDate())); // t = dfo.format(df.parse(comment.getCreationDate().getTime().toString())); // } catch (java.text.ParseException e) { // t = "Invalid date: " + comment.getCreationDate().getTime().toString(); // } creationDate.setText(t); gbc.gridx++; gbc.insets = new Insets(upperMargin, 0, 0, 0); add(creationDate, gbc); String dehtmlizedBody = Html2text.translate(comment.getBody()); if (StackTraceDetector.containsStackTrace(dehtmlizedBody)) { int stackTraceCounter = ip.incrementStackTraceCounter(); tabs.add("Comment Stack Trace #" + (++stackTraceCounter), new StackTracePanel(dehtmlizedBody, ip.getProject())); gbc.gridx++; gbc.insets = new Insets(upperMargin, Constants.DIALOG_MARGIN / 2, 0, 0); JLabel traceNumber = new WhiteLabel(); traceNumber.setText("Stack Trace #" + stackTraceCounter); traceNumber.setForeground(Color.RED); add(traceNumber, gbc); } // filler gbc.gridx++; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.weightx = 1.0; JPanel filler = new JPanel(); filler.setBackground(com.intellij.util.ui.UIUtil.getTextFieldBackground()); filler.setOpaque(true); gbc.insets = new Insets(upperMargin, 0, 0, 0); add(filler, gbc); int gridwidth = gbc.gridx + 1; commentBody.setEditable(false); commentBody.setOpaque(true); commentBody.setBackground(com.intellij.util.ui.UIUtil.getTextFieldBackground()); commentBody.setMargin(new Insets(0, 2 * Constants.DIALOG_MARGIN, 0, 0)); commentBody.setContentType("text/html"); commentBody.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, true); // JEditorPane does not do XHTML :( String bodyFixed = comment.getBody().replace("/>", ">"); commentBody.setText("<html><head></head><body>" + bodyFixed + "</body></html>"); commentBody.addHyperlinkListener(new HyperlinkListener() { public void hyperlinkUpdate(HyperlinkEvent e) { if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED && e.getURL() != null) { BrowserUtil.launchBrowser(e.getURL().toString()); } } }); gbc.gridx = 0; gbc.gridy = 1; gbc.gridwidth = gridwidth; gbc.weightx = 1.0; gbc.weighty = 1.0; gbc.fill = GridBagConstraints.BOTH; gbc.insets = new Insets(0, 0, 0, 0); add(commentBody, gbc); addMouseListener(headerListener); }
From source file:com.baidubce.services.lss.LssClient.java
License:Open Source License
/** * Get your live session with token by live session id. * * @param sessionId Live session id.//www. j ava 2 s . c o m * @param timeoutInMinute Timeout of token. * * @return Your live session with token. */ public GetSessionResponse getSessionWithToken(String sessionId, Integer timeoutInMinute) { GetSessionResponse getSessionResponse = getSession(sessionId); if (timeoutInMinute == null) { return getSessionResponse; } DateTime dateTime = new DateTime(DateTimeZone.UTC); DateTime expireTime = dateTime.plusMinutes(timeoutInMinute); DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss'Z'"); String expire = formatter.print(expireTime); GetSecurityPolicyResponse getSecurityPolicyResponse = getSecurityPolicy( getSessionResponse.getSecurityPolicy()); if (getSecurityPolicyResponse.getAuth().getPlay()) { String hlsUrl = getSessionResponse.getPlay().getHlsUrl(); String rtmpUrl = getSessionResponse.getPlay().getRtmpUrl(); if (hlsUrl != null) { String hlsToken = LssUtils.hmacSha256(String.format("/%s/live.m3u8;%s", sessionId, expire), getSecurityPolicyResponse.getAuth().getKey()); if (hlsUrl.lastIndexOf('?') == -1) { hlsUrl += String.format("?token=%s&expire=%s", hlsToken, expire); } else { hlsUrl += String.format("&token=%s&expire=%s", hlsToken, expire); } getSessionResponse.getPlay().setHlsUrl(hlsUrl); } if (rtmpUrl != null) { String rtmpToken = LssUtils.hmacSha256(String.format("%s;%s", sessionId, expire), getSecurityPolicyResponse.getAuth().getKey()); rtmpUrl += String.format("?token=%s&expire=%s", rtmpToken, expire); getSessionResponse.getPlay().setRtmpUrl(rtmpUrl); } } if (getSecurityPolicyResponse.getAuth().getPush()) { String pushUrl = getSessionResponse.getPublish().getPushUrl(); String pushToken = LssUtils.hmacSha256( String.format("%s;%s", getSessionResponse.getPublish().getPushStream(), expire), getSecurityPolicyResponse.getAuth().getKey()); pushUrl += String.format("?token=%s&expire=%s", pushToken, expire); getSessionResponse.getPublish().setPushUrl(pushUrl); } return getSessionResponse; }
From source file:com.bancandes.dao.Consultas.java
public static String formatDate(DateTime dt) { DateTimeFormatter dtf = DateTimeFormat.forPattern("yyyy/mm/dd HH:mm:ss"); return dtf.print(dt); }