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

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

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

OffsetDateTime.parse介绍

[英]Obtains an instance of OffsetDateTime from a text string such as 2007-12-03T10:15:30+01:00.

The string must represent a valid date-time and is parsed using java.time.format.DateTimeFormatters#isoOffsetDateTime().
[中]从文本字符串(如2007-12-03T10:15:30+01:00)获取OffsetDateTime的实例。
字符串必须表示有效的日期和时间,并使用java进行解析。时间总体安排DateTimeFormatters#IsOffsetDateTime()。

代码示例

代码示例来源:origin: org.assertj/assertj-core

  1. /**
  2. * {@inheritDoc}
  3. */
  4. @Override
  5. protected OffsetDateTime parse(String offsetDateTimeAsString) {
  6. return OffsetDateTime.parse(offsetDateTimeAsString);
  7. }

代码示例来源:origin: org.assertj/assertj-core

  1. private static Object[] convertToOffsetDateTimeArray(String... dateTimesAsString) {
  2. OffsetDateTime[] dates = new OffsetDateTime[dateTimesAsString.length];
  3. for (int i = 0; i < dateTimesAsString.length; i++) {
  4. dates[i] = OffsetDateTime.parse(dateTimesAsString[i]);
  5. }
  6. return dates;
  7. }

代码示例来源:origin: joel-costigliola/assertj-core

  1. private static Object[] convertToOffsetDateTimeArray(String... dateTimesAsString) {
  2. OffsetDateTime[] dates = new OffsetDateTime[dateTimesAsString.length];
  3. for (int i = 0; i < dateTimesAsString.length; i++) {
  4. dates[i] = OffsetDateTime.parse(dateTimesAsString[i]);
  5. }
  6. return dates;
  7. }

代码示例来源:origin: joel-costigliola/assertj-core

  1. /**
  2. * {@inheritDoc}
  3. */
  4. @Override
  5. protected OffsetDateTime parse(String offsetDateTimeAsString) {
  6. return OffsetDateTime.parse(offsetDateTimeAsString);
  7. }

代码示例来源:origin: dropwizard/dropwizard

  1. @Override
  2. protected OffsetDateTime parse(@Nullable final String input) throws Exception {
  3. return OffsetDateTime.parse(input);
  4. }
  5. }

代码示例来源:origin: oracle/helidon

  1. /**
  2. * Maps {@code stringValue} to {@code OffsetDateTime}.
  3. *
  4. * @param stringValue source value as a {@code String}
  5. * @return mapped {@code stringValue} to {@code OffsetDateTime}
  6. * @see OffsetDateTime#parse(CharSequence)
  7. */
  8. public static OffsetDateTime toOffsetDateTime(String stringValue) {
  9. return OffsetDateTime.parse(stringValue);
  10. }

代码示例来源:origin: org.springframework.boot/spring-boot

  1. @Override
  2. public OffsetDateTime parse(String text, Locale locale) throws ParseException {
  3. return OffsetDateTime.parse(text, DateTimeFormatter.ISO_OFFSET_DATE_TIME);
  4. }

代码示例来源:origin: prestodb/presto

  1. @Override
  2. protected OffsetDateTime deserialize(String key, DeserializationContext ctxt) throws IOException {
  3. try {
  4. return OffsetDateTime.parse(key, DateTimeFormatter.ISO_OFFSET_DATE_TIME);
  5. } catch (DateTimeException e) {
  6. return _handleDateTimeException(ctxt, OffsetDateTime.class, e, key);
  7. }
  8. }
  9. }

代码示例来源:origin: codecentric/spring-boot-admin

  1. @Nullable
  2. private static Instant getInstant(Object o) {
  3. try {
  4. if (o instanceof String) {
  5. return OffsetDateTime.parse((String) o, TIMESTAMP_PATTERN).toInstant();
  6. } else if (o instanceof Long) {
  7. return Instant.ofEpochMilli((Long) o);
  8. }
  9. } catch (DateTimeException | ClassCastException e) {
  10. return null;
  11. }
  12. return null;
  13. }
  14. }

代码示例来源:origin: SonarSource/sonarqube

  1. /**
  2. * @param s string in format {@link #DATETIME_FORMAT}
  3. * @throws SonarException when string cannot be parsed
  4. * @since 6.6
  5. */
  6. public static OffsetDateTime parseOffsetDateTime(String s) {
  7. try {
  8. return OffsetDateTime.parse(s, DATETIME_FORMATTER);
  9. } catch (DateTimeParseException e) {
  10. throw MessageException.of("The date '" + s + "' does not respect format '" + DATETIME_FORMAT + "'", e);
  11. }
  12. }

代码示例来源:origin: spring-projects/spring-framework

  1. @Override
  2. public TemporalAccessor parse(String text, Locale locale) throws ParseException {
  3. DateTimeFormatter formatterToUse = DateTimeContextHolder.getFormatter(this.formatter, locale);
  4. if (LocalDate.class == this.temporalAccessorType) {
  5. return LocalDate.parse(text, formatterToUse);
  6. }
  7. else if (LocalTime.class == this.temporalAccessorType) {
  8. return LocalTime.parse(text, formatterToUse);
  9. }
  10. else if (LocalDateTime.class == this.temporalAccessorType) {
  11. return LocalDateTime.parse(text, formatterToUse);
  12. }
  13. else if (ZonedDateTime.class == this.temporalAccessorType) {
  14. return ZonedDateTime.parse(text, formatterToUse);
  15. }
  16. else if (OffsetDateTime.class == this.temporalAccessorType) {
  17. return OffsetDateTime.parse(text, formatterToUse);
  18. }
  19. else if (OffsetTime.class == this.temporalAccessorType) {
  20. return OffsetTime.parse(text, formatterToUse);
  21. }
  22. else {
  23. throw new IllegalStateException("Unsupported TemporalAccessor type: " + this.temporalAccessorType);
  24. }
  25. }

代码示例来源:origin: com.fasterxml.jackson.datatype/jackson-datatype-jsr310

  1. @Override
  2. protected OffsetDateTime deserialize(String key, DeserializationContext ctxt) throws IOException {
  3. try {
  4. return OffsetDateTime.parse(key, DateTimeFormatter.ISO_OFFSET_DATE_TIME);
  5. } catch (DateTimeException e) {
  6. return _handleDateTimeException(ctxt, OffsetDateTime.class, e, key);
  7. }
  8. }
  9. }

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

  1. public static long parseDateTime(String dateTimeStr) {
  2. OffsetDateTime dateTime = OffsetDateTime.parse(dateTimeStr, DateTimeFormatter.ISO_DATE_TIME);
  3. return dateTime.toInstant().toEpochMilli();
  4. }

代码示例来源:origin: knowm/XChange

  1. public static Date toDate(String dateString) {
  2. try {
  3. return dateParserNoMillis().parse(dateString);
  4. } catch (ParseException e) {
  5. OffsetDateTime offsetDateTime = OffsetDateTime.parse(dateString);
  6. return new Date(offsetDateTime.toInstant().toEpochMilli());
  7. }
  8. }

代码示例来源:origin: org.springframework/spring-context

  1. @Override
  2. public TemporalAccessor parse(String text, Locale locale) throws ParseException {
  3. DateTimeFormatter formatterToUse = DateTimeContextHolder.getFormatter(this.formatter, locale);
  4. if (LocalDate.class == this.temporalAccessorType) {
  5. return LocalDate.parse(text, formatterToUse);
  6. }
  7. else if (LocalTime.class == this.temporalAccessorType) {
  8. return LocalTime.parse(text, formatterToUse);
  9. }
  10. else if (LocalDateTime.class == this.temporalAccessorType) {
  11. return LocalDateTime.parse(text, formatterToUse);
  12. }
  13. else if (ZonedDateTime.class == this.temporalAccessorType) {
  14. return ZonedDateTime.parse(text, formatterToUse);
  15. }
  16. else if (OffsetDateTime.class == this.temporalAccessorType) {
  17. return OffsetDateTime.parse(text, formatterToUse);
  18. }
  19. else if (OffsetTime.class == this.temporalAccessorType) {
  20. return OffsetTime.parse(text, formatterToUse);
  21. }
  22. else {
  23. throw new IllegalStateException("Unsupported TemporalAccessor type: " + this.temporalAccessorType);
  24. }
  25. }

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

  1. public static long parseDateAsDuration(String dateTimeStr) {
  2. try {
  3. OffsetDateTime dateTime = OffsetDateTime.parse(dateTimeStr, DateTimeFormatter.ISO_DATE_TIME);
  4. Duration duration = Duration.between(OffsetDateTime.now(), dateTime);
  5. return duration.toMillis();
  6. } catch (Exception e) {
  7. return TimeUtils.parseTimeString(dateTimeStr);
  8. }
  9. }

代码示例来源:origin: com.thoughtworks.xstream/xstream

  1. @Override
  2. public Object fromString(final String str) {
  3. try {
  4. return OffsetDateTime.parse(str);
  5. } catch (final DateTimeParseException e) {
  6. final ConversionException exception = new ConversionException("Cannot parse value as offset date time", e);
  7. exception.add("value", str);
  8. throw exception;
  9. }
  10. }

代码示例来源:origin: google/data-transfer-project

  1. private static CalendarEventModel.CalendarEventTime getEventTime(EventDateTime dateTime) {
  2. if (dateTime == null) {
  3. return null;
  4. }
  5. OffsetDateTime offsetDateTime;
  6. if (dateTime.getDate() == null) {
  7. offsetDateTime = OffsetDateTime.parse(dateTime.getDateTime().toString());
  8. } else {
  9. offsetDateTime =
  10. OffsetDateTime.from(
  11. LocalDate.parse(dateTime.getDate().toString()).atStartOfDay(ZoneId.of("UTC")));
  12. }
  13. return new CalendarEventModel.CalendarEventTime(offsetDateTime, dateTime.getDate() != null);
  14. }

代码示例来源:origin: alibaba/fastjson

  1. OffsetDateTime offsetDateTime = OffsetDateTime.parse(text);

代码示例来源:origin: jdbi/jdbi

  1. @Override
  2. public void logBeforeExecution(StatementContext ctx) {
  3. String toString = ctx.getBinding()
  4. .findForName(name, ctx)
  5. .orElseThrow(AssertionError::new)
  6. .toString();
  7. insertedTimestamp = OffsetDateTime.parse(toString);
  8. insertedSqlTimestamp = Timestamp.from(insertedTimestamp.toInstant());
  9. }

相关文章