java.time.OffsetDateTime.toString()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(8.6k)|赞(0)|评价(0)|浏览(143)

本文整理了Java中java.time.OffsetDateTime.toString()方法的一些代码示例,展示了OffsetDateTime.toString()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。OffsetDateTime.toString()方法的具体详情如下:
包路径:java.time.OffsetDateTime
类名称:OffsetDateTime
方法名:toString

OffsetDateTime.toString介绍

[英]Outputs this date-time as a String, such as 2007-12-03T10:15:30+01:00.

The output will be one of the following ISO-8601 formats:

  • yyyy-MM-dd'T'HH:mmXXXXX
  • yyyy-MM-dd'T'HH:mm:ssXXXXX
  • yyyy-MM-dd'T'HH:mm:ss.SSSXXXXX
  • yyyy-MM-dd'T'HH:mm:ss.SSSSSSXXXXX
  • yyyy-MM-dd'T'HH:mm:ss.SSSSSSSSSXXXXX

The format used will be the shortest that outputs the full value of the time where the omitted parts are implied to be zero.
[中]以字符串形式输出此日期时间,例如2007-12-03T10:15:30+01:00。
输出将是以下ISO-8601格式之一:
*yyyy MM dd'HH:mmXXXXX
*yyyy MM dd'HH:MM:ssXXXXX
*yyyy-MM-dd'HH:MM:ss。SSSxxx
*yyyy-MM-dd'HH:MM:ss。SSSSXXXXX
*yyyy-MM-dd'HH:MM:ss。SSSSXXXXX
所使用的格式将是最短的,输出省略部分暗示为零的时间的完整值。

代码示例

代码示例来源:origin: kiegroup/jbpm

  1. @Test(timeout=10000)
  2. public void testTimerStartDateISO() throws Exception {
  3. NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("StartProcess", 1);
  4. byte[] content = IoUtils.readBytesFromInputStream(this.getClass().getResourceAsStream("/BPMN2-TimerStartDate.bpmn2"));
  5. String processContent = new String(content, "UTF-8");
  6. OffsetDateTime plusTwoSeconds = OffsetDateTime.now().plusSeconds(2);
  7. processContent = processContent.replaceFirst("#\\{date\\}", plusTwoSeconds.toString());
  8. Resource resource = ResourceFactory.newReaderResource(new StringReader(processContent));
  9. resource.setSourcePath("/BPMN2-TimerStartDate.bpmn2");
  10. resource.setTargetPath("/BPMN2-TimerStartDate.bpmn2");
  11. KieBase kbase = createKnowledgeBaseFromResources(resource);
  12. ksession = createKnowledgeSession(kbase);
  13. ksession.addEventListener(countDownListener);
  14. final List<Long> list = new ArrayList<Long>();
  15. ksession.addEventListener(new DefaultProcessEventListener() {
  16. public void beforeProcessStarted(ProcessStartedEvent event) {
  17. list.add(event.getProcessInstance().getId());
  18. }
  19. });
  20. assertThat(list.size()).isEqualTo(0);
  21. countDownListener.waitTillCompleted();
  22. assertThat(list.size()).isEqualTo(1);
  23. }

代码示例来源:origin: kiegroup/jbpm

  1. @Test(timeout=10000)
  2. public void testIntermediateCatchEventTimerDateISO() throws Exception {
  3. NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("timer", 1);
  4. KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-IntermediateCatchEventTimerDateISO.bpmn2");
  5. ksession = createKnowledgeSession(kbase);
  6. ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new DoNothingWorkItemHandler());
  7. ksession.addEventListener(countDownListener);
  8. HashMap<String, Object> params = new HashMap<String, Object>();
  9. OffsetDateTime plusTwoSeconds = OffsetDateTime.now().plusSeconds(2);
  10. params.put("date", plusTwoSeconds.toString());
  11. ProcessInstance processInstance = ksession.startProcess("IntermediateCatchEvent", params);
  12. assertProcessInstanceActive(processInstance);
  13. // now wait for 1 second for timer to trigger
  14. countDownListener.waitTillCompleted();
  15. assertProcessInstanceFinished(processInstance, ksession);
  16. }

代码示例来源:origin: kiegroup/jbpm

  1. @Test(timeout=10000)
  2. public void testTimerBoundaryEventDateISO() throws Exception {
  3. NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("TimerEvent", 1);
  4. KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-TimerBoundaryEventDateISO.bpmn2");
  5. ksession = createKnowledgeSession(kbase);
  6. ksession.addEventListener(countDownListener);
  7. ksession.getWorkItemManager().registerWorkItemHandler("MyTask", new DoNothingWorkItemHandler());
  8. HashMap<String, Object> params = new HashMap<String, Object>();
  9. OffsetDateTime plusTwoSeconds = OffsetDateTime.now().plusSeconds(2);
  10. params.put("date", plusTwoSeconds.toString());
  11. ProcessInstance processInstance = ksession.startProcess("TimerBoundaryEvent", params);
  12. assertProcessInstanceActive(processInstance);
  13. countDownListener.waitTillCompleted();
  14. ksession = restoreSession(ksession, true);
  15. assertProcessInstanceFinished(processInstance, ksession);
  16. }

代码示例来源:origin: neo4j/neo4j-ogm

  1. @Override
  2. public String toGraphProperty(OffsetDateTime value) {
  3. if (value == null) {
  4. return null;
  5. }
  6. return value.toString();
  7. }

代码示例来源:origin: io.permazen/permazen-coreapi

  1. @Override
  2. public String toParseableString(OffsetDateTime offsetDateTime) {
  3. return offsetDateTime.toString();
  4. }
  5. }

代码示例来源:origin: org.jsimpledb/jsimpledb-coreapi

  1. @Override
  2. public String toParseableString(OffsetDateTime offsetDateTime) {
  3. return offsetDateTime.toString();
  4. }
  5. }

代码示例来源:origin: com.guestful.module/guestful.module.jsr310-extensions

  1. /**
  2. * Output a string in ISO8601 interval format.
  3. * <p>
  4. * From version 2.1, the string includes the time zone offset.
  5. *
  6. * @return re-parsable string (in the default zone)
  7. */
  8. @Override
  9. public String toString() {
  10. return start.toOffsetDateTime().toString() + "/" + end.toOffsetDateTime().toString();
  11. }

代码示例来源:origin: io.helixservice/helix-rest

  1. private JsonObject heartBeatData() {
  2. return new JsonObject()
  3. .put(GIT_COMMIT_ID, commitId)
  4. .put(GIT_REMOTE_URL, remoteUrl)
  5. .put(APP_VERSION, appVersion)
  6. .put(UP_SINCE, startedAt.toString())
  7. .put(UP_TIME, currentUpTime());
  8. }

代码示例来源:origin: rocks.xmpp/xmpp-extensions-common

  1. /**
  2. * Creates a header with a start date.
  3. *
  4. * @param dateTime The start date.
  5. * @return The header.
  6. * @see <a href="https://xmpp.org/extensions/xep-0149.html">XEP-0149: Time Periods</a>
  7. */
  8. public static Header ofStartDate(OffsetDateTime dateTime) {
  9. return new Header("Start", dateTime.toString());
  10. }

代码示例来源:origin: org.openbase.bco/ontology.lib

  1. /**
  2. * Method returns the current dateTime.
  3. *
  4. * @return String in format yyyy-MM-dd'T'HH:mm:ss.SSSXXX
  5. */
  6. public static String getCurrentDateTime() {
  7. // final SimpleDateFormat simpleDateFormat = new SimpleDateFormat(OntConfig.DATE_TIME, Locale.ENGLISH);
  8. // final Date date = new Date();
  9. return OffsetDateTime.now().toString();
  10. }

代码示例来源:origin: ch.rasc/bsoncodec

  1. @Override
  2. public void encode(BsonWriter writer, OffsetDateTime value,
  3. EncoderContext encoderContext) {
  4. writer.writeString(value.toString());
  5. }

代码示例来源:origin: rocks.xmpp/xmpp-extensions-common

  1. @Override
  2. public final String toString() {
  3. OffsetDateTime dateTime = getDateTime();
  4. if (dateTime != null) {
  5. return dateTime.toString();
  6. }
  7. return super.toString();
  8. }
  9. }

代码示例来源:origin: stackoverflow.com

  1. String dateTimestr = "2015-02-05T02:05:17.000+00:00";
  2. OffsetDateTime dateTime = OffsetDateTime.parse(dateTimestr);
  3. if ((dateTime.getNano() == 0) && (dateTimestr.length() > 25 ))
  4. System.out.println(dateTime.toLocalDateTime() + ".000Z");
  5. else
  6. System.out.println(dateTime.toString());

代码示例来源:origin: Netflix/iceberg

  1. @Override
  2. public String read(String ignored) {
  3. return ChronoUnit.MILLIS.addTo(EPOCH, column.nextLong()).toString();
  4. }
  5. }

代码示例来源:origin: Netflix/iceberg

  1. @Override
  2. public String read(String ignored) {
  3. return ChronoUnit.MICROS.addTo(EPOCH, column.nextLong()).toString();
  4. }
  5. }

代码示例来源:origin: com.github.robozonky/robozonky-common

  1. @Override
  2. public Boolean call() {
  3. final String sectionName = instanceState.getSectionName();
  4. final StateStorage backend = instanceState.getStorage();
  5. actions.forEach(a -> a.accept(backend, sectionName));
  6. backend.setValue(sectionName, Constants.LAST_UPDATED_KEY.getValue(), DateUtil.offsetNow().toString());
  7. return backend.store();
  8. }
  9. }

代码示例来源:origin: org.openbase.bco/ontology.lib

  1. private void deleteObservations() throws CouldNotPerformException, InterruptedException {
  2. //TODO
  3. final String dateTimeFrom = StringModifier.convertToLiteral(OffsetDateTime.of(2017, 4, 19, 0, 0, 0, 0, ZoneOffset.UTC).toString(), XsdType.DATE_TIME);
  4. final String dateTimeUntil = StringModifier.convertToLiteral(OffsetDateTime.of(2017, 4, 20, 0, 0, 0, 0, ZoneOffset.UTC).toString(), XsdType.DATE_TIME);
  5. SparqlHttp.uploadSparqlRequest(QueryExpression.deleteObservationOfTimeFrame(dateTimeFrom, dateTimeUntil), OntConfig.getOntologyDbUrl(), 0);
  6. }
  7. }

代码示例来源:origin: org.pageseeder.bridge/pso-bridge

  1. @Override
  2. public void toXML(XMLWriter xml) throws IOException {
  3. xml.openElement("modifiedby");
  4. xml.attribute("date", this._date.toString()); // TODO date formatting
  5. this._member.toXMLAttributes(xml);
  6. xml.closeElement();
  7. }

代码示例来源:origin: com.github.robozonky/robozonky-notifications

  1. public void setDelinquent(final SessionInfo sessionInfo, final Investment investment) {
  2. if (this.isDelinquent(sessionInfo, investment)) {
  3. return;
  4. }
  5. TenantState.of(sessionInfo)
  6. .in(DelinquencyTracker.class)
  7. .update(b -> b.put(toId(investment), DateUtil.offsetNow().toString()));
  8. }

代码示例来源:origin: org.pageseeder.bridge/pso-bridge

  1. @Override
  2. public void toXML(XMLWriter xml) throws IOException {
  3. xml.openElement("assignedto");
  4. xml.attribute("date", this._date.toString()); // TODO date formatting
  5. this._member.toXMLAttributes(xml);
  6. xml.element("fullname", this._member.getFirstname()+" "+this._member.getSurname());
  7. xml.closeElement();
  8. }

相关文章