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

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

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

ZonedDateTime.withLaterOffsetAtOverlap介绍

[英]Returns a copy of this date-time changing the zone offset to the later of the two valid offsets at a local time-line overlap.

This method only has any effect when the local time-line overlaps, such as at an autumn daylight savings cutover. In this scenario, there are two valid offsets for the local date-time. Calling this method will return a zoned date-time with the later of the two selected.

If this method is called when it is not an overlap, thisis returned.

This instance is immutable and unaffected by this method call.
[中]返回此日期时间的副本,将分区偏移更改为本地时间线重叠处两个有效偏移中的较晚者。
此方法仅在本地时间线重叠时有效,例如在秋季夏令时切换时。在这种情况下,本地日期时间有两个有效的偏移量。调用此方法将返回一个分区日期时间,并选择两者中的较晚者。
如果在不重叠的情况下调用此方法,则返回this。
此实例是不可变的,不受此方法调用的影响。

代码示例

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

DateTimeFormatterBuilder dtfb = new DateTimeFormatterBuilder();
dtfb.append(DateTimeFormatter.ISO_LOCAL_DATE);
dtfb.appendLiteral(' ');
dtfb.append(DateTimeFormatter.ISO_LOCAL_TIME);
DateTimeFormatter dtf = dtfb.toFormatter();
ZoneId shanghai = ZoneId.of("Asia/Shanghai");

String str3 = "1927-12-31 23:54:07";  
String str4 = "1927-12-31 23:54:08";  

ZonedDateTime zdt3 = LocalDateTime.parse(str3, dtf).atZone(shanghai);
ZonedDateTime zdt4 = LocalDateTime.parse(str4, dtf).atZone(shanghai);

Duration durationAtEarlierOffset = Duration.between(zdt3.withEarlierOffsetAtOverlap(), zdt4.withEarlierOffsetAtOverlap());

Duration durationAtLaterOffset = Duration.between(zdt3.withLaterOffsetAtOverlap(), zdt4.withLaterOffsetAtOverlap());

代码示例来源:origin: org.elasticsearch/elasticsearch

public ZonedDateTime withLaterOffsetAtOverlap() {
  return dt.withLaterOffsetAtOverlap();
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch

public ZonedDateTime withLaterOffsetAtOverlap() {
  return dt.withLaterOffsetAtOverlap();
}

代码示例来源:origin: apache/servicemix-bundles

public ZonedDateTime withLaterOffsetAtOverlap() {
  return dt.withLaterOffsetAtOverlap();
}

代码示例来源:origin: hibernate/hibernate-search

@Test
public void testZonedDateTime() throws Exception {
  // CET DST rolls back at 2011-10-30 2:59:59 (+02) to 2011-10-30 2:00:00 (+01)
  // Credit: user leonbloy at http://stackoverflow.com/a/18794412/6692043
  LocalDateTime localDateTime = LocalDateTime.of( 2011, 10, 30, 2, 50, 0, 0 );
  ZonedDateTime value = localDateTime.atZone( ZoneId.of( "CET" ) ).withLaterOffsetAtOverlap();
  Sample sample = new Sample( 1L, "ZonedDateTime example" );
  sample.zonedDateTime = value;
  assertThatFieldIsIndexed( "zonedDateTime", value, sample );
}

代码示例来源:origin: hibernate/hibernate-search

@Test
public void testZonedDateTimeNanoseconds() throws Exception {
  // CET DST rolls back at 2011-10-30 2:59:59 (+02) to 2011-10-30 2:00:00 (+01)
  // Credit: user leonbloy at http://stackoverflow.com/a/18794412/6692043
  LocalDateTime localDateTime = LocalDateTime.of( 2011, 10, 30, 2, 50, 0, 7 );
  ZonedDateTime value = localDateTime.atZone( ZoneId.of( "CET" ) ).withLaterOffsetAtOverlap();
  Sample sample = new Sample( 1L, "ZonedDateTime example" );
  sample.zonedDateTime = value;
  // Elasticsearch only has millisecond-precision, so the "fields" value is missing the nanoseconds
  // Also, the "fields" attribute only ever contains UTC date/times
  assertThatFieldIsFormatted( sample, "zonedDateTime", "2011-10-30T02:50:00.000000007+01:00[CET]", "2011-10-30T01:50:00.000+00:00[UTC]" );
}

相关文章

ZonedDateTime类方法