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

x33g5p2x  于2022-02-05 转载在 其他  
字(6.5k)|赞(0)|评价(0)|浏览(263)

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

ZonedDateTime.parse介绍

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

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

代码示例

代码示例来源:origin: Graylog2/graylog2-server

@Override
public ZonedDateTime createdAt() {
  return ZonedDateTime.parse("2018-03-23T15:00:00Z");
}

代码示例来源:origin: Graylog2/graylog2-server

@Override
public ZonedDateTime createdAt() {
  return ZonedDateTime.parse("2017-01-10T15:01:00Z");
}

代码示例来源:origin: Graylog2/graylog2-server

@Override
public ZonedDateTime createdAt() {
  return ZonedDateTime.parse("2016-11-16T17:21:00Z");
}

代码示例来源:origin: Graylog2/graylog2-server

@Override
public ZonedDateTime createdAt() {
  return ZonedDateTime.parse("2016-11-16T17:22:00Z");
}

代码示例来源:origin: Graylog2/graylog2-server

@Override
public ZonedDateTime createdAt() {
  return ZonedDateTime.parse("2016-12-15T16:39:00Z");
}

代码示例来源:origin: Graylog2/graylog2-server

@Override
public ZonedDateTime createdAt() {
  return ZonedDateTime.parse("2016-11-30T14:15:00Z");
}

代码示例来源:origin: Graylog2/graylog2-server

@Override
public ZonedDateTime createdAt() {
  return ZonedDateTime.parse("2018-09-24T11:16:44Z");
}

代码示例来源:origin: Graylog2/graylog2-server

@Override
public ZonedDateTime createdAt() {
  return ZonedDateTime.parse("2018-02-12T16:50:00Z");
}

代码示例来源:origin: Graylog2/graylog2-server

@Override
public ZonedDateTime createdAt() {
  return ZonedDateTime.parse("2018-06-01T15:15:00Z");
}

代码示例来源:origin: Graylog2/graylog2-server

@Override
public ZonedDateTime createdAt() {
  return ZonedDateTime.parse("2016-11-22T17:45:00Z");
}

代码示例来源:origin: Graylog2/graylog2-server

@Override
public ZonedDateTime createdAt() {
  return ZonedDateTime.parse("2016-11-25T14:24:00Z");
}

代码示例来源:origin: Graylog2/graylog2-server

@Override
public ZonedDateTime createdAt() {
  return ZonedDateTime.parse("2016-11-24T10:47:00Z");
}

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

@Override
  protected ZonedDateTime parse(@Nullable final String input) throws Exception {
    return ZonedDateTime.parse(input);
  }
}

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

@Override
  protected ZonedDateTime deserialize(String key, DeserializationContext ctxt) throws IOException {
    // not serializing timezone data yet
    try {
      return ZonedDateTime.parse(key, DateTimeFormatter.ISO_OFFSET_DATE_TIME);
    } catch (DateTimeException e) {
      return _handleDateTimeException(ctxt, ZonedDateTime.class, e, key);
    }
  }
}

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

/**
 * Obtains an instance of {@link ZonedDateTime} from a string representation in ISO date format.
 * Note that the {@link ZonedDateTime} created from the given String is built in the {@link java.time.ZoneId} of the
 * actual {@link ZonedDateTime}.
 * @param dateTimeAsString the string to parse
 * @return the parsed {@link ZonedDateTime}
 */
@Override
protected ZonedDateTime parse(String dateTimeAsString) {
 ZonedDateTime zonedDateTime = ZonedDateTime.parse(dateTimeAsString, DateTimeFormatter.ISO_DATE_TIME);
 return sameInstantInActualTimeZone(zonedDateTime);
}

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

@Override
public TemporalAccessor parse(String text, Locale locale) throws ParseException {
  DateTimeFormatter formatterToUse = DateTimeContextHolder.getFormatter(this.formatter, locale);
  if (LocalDate.class == this.temporalAccessorType) {
    return LocalDate.parse(text, formatterToUse);
  }
  else if (LocalTime.class == this.temporalAccessorType) {
    return LocalTime.parse(text, formatterToUse);
  }
  else if (LocalDateTime.class == this.temporalAccessorType) {
    return LocalDateTime.parse(text, formatterToUse);
  }
  else if (ZonedDateTime.class == this.temporalAccessorType) {
    return ZonedDateTime.parse(text, formatterToUse);
  }
  else if (OffsetDateTime.class == this.temporalAccessorType) {
    return OffsetDateTime.parse(text, formatterToUse);
  }
  else if (OffsetTime.class == this.temporalAccessorType) {
    return OffsetTime.parse(text, formatterToUse);
  }
  else {
    throw new IllegalStateException("Unsupported TemporalAccessor type: " + this.temporalAccessorType);
  }
}

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

@Test
public void parseDates() {
  ContentDisposition disposition = ContentDisposition
      .parse("attachment; creation-date=\"Mon, 12 Feb 2007 10:15:30 -0500\"; " +
          "modification-date=\"Tue, 13 Feb 2007 10:15:30 -0500\"; " +
          "read-date=\"Wed, 14 Feb 2007 10:15:30 -0500\"");
  DateTimeFormatter formatter = DateTimeFormatter.RFC_1123_DATE_TIME;
  assertEquals(ContentDisposition.builder("attachment")
      .creationDate(ZonedDateTime.parse("Mon, 12 Feb 2007 10:15:30 -0500", formatter))
      .modificationDate(ZonedDateTime.parse("Tue, 13 Feb 2007 10:15:30 -0500", formatter))
      .readDate(ZonedDateTime.parse("Wed, 14 Feb 2007 10:15:30 -0500", formatter)).build(), disposition);
}

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

@Test
public void checkModifiedTimestampWithLengthPart() {
  long epochTime = ZonedDateTime.parse(CURRENT_TIME, RFC_1123_DATE_TIME).toInstant().toEpochMilli();
  servletRequest.setMethod("GET");
  servletRequest.addHeader("If-Modified-Since", "Wed, 08 Apr 2014 09:57:42 GMT; length=13774");
  assertFalse(request.checkNotModified(epochTime));
  assertEquals(200, servletResponse.getStatus());
  assertEquals(epochTime / 1000, servletResponse.getDateHeader("Last-Modified") / 1000);
}

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

@Test
public void checkNotModifiedTimestampWithLengthPart() {
  long epochTime = ZonedDateTime.parse(CURRENT_TIME, RFC_1123_DATE_TIME).toInstant().toEpochMilli();
  servletRequest.setMethod("GET");
  servletRequest.addHeader("If-Modified-Since", "Wed, 09 Apr 2014 09:57:42 GMT; length=13774");
  assertTrue(request.checkNotModified(epochTime));
  assertEquals(304, servletResponse.getStatus());
  assertEquals(epochTime / 1000, servletResponse.getDateHeader("Last-Modified") / 1000);
}

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

@Test
public void parseInvalidDates() {
  ContentDisposition disposition = ContentDisposition
      .parse("attachment; creation-date=\"-1\"; modification-date=\"-1\"; " +
          "read-date=\"Wed, 14 Feb 2007 10:15:30 -0500\"");
  DateTimeFormatter formatter = DateTimeFormatter.RFC_1123_DATE_TIME;
  assertEquals(ContentDisposition.builder("attachment")
      .readDate(ZonedDateTime.parse("Wed, 14 Feb 2007 10:15:30 -0500", formatter)).build(), disposition);
}

相关文章

ZonedDateTime类方法