Java ChronoZonedDateTime withLaterOffsetAtOverlap()方法及示例

Java ChronoZonedDateTime withLaterOffsetAtOverlap()方法及示例

ChronoZonedDateTime 接口的 withLaterOffsetAtOverlap() 方法是用来返回这个ChronoZonedDateTime对象的一个副本,在将区域偏移量改为本地时间线重叠处的两个有效偏移量中较晚的一个。重叠发生在日光节约时间结束后,一个小时被返回到时间线上。因此,本地日期时间有两个有效的偏移量,调用withLaterOffsetAtOverlap方法将返回一个ChronoZonedDateTime,其偏移量为两个区域中较晚的那个。如果在不是重叠的时候调用这个方法,就会返回这个。这个实例是不可改变的,不受这个方法调用的影响。

语法

ChronoZonedDateTime withLaterOffsetAtOverlap()

参数: 该方法不接受任何参数。

返回值: 该方法返回一个基于该日期时间的 ChronoZonedDateTime ,并带有较晚的偏移。

以下程序说明了withLaterOffsetAtOverlap()方法。

程序1 :

// Java program to demonstrate
// ChronoZonedDateTime.withLaterOffsetAtOverlap() method
  
import java.time.*;
import java.time.chrono.*;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // create a ChronoZonedDateTime object
        ChronoZonedDateTime zonedDT
            = ZonedDateTime.of(
                LocalDateTime.of(2018, 11, 4, 1, 25, 43),
                ZoneId.of("US/Central"));
  
        // print ChronoZonedDateTime
        System.out.println("Before withLaterOffsetAtOverlap(): "
                           + zonedDT);
  
        // apply withLaterOffsetAtOverlap()
        ChronoZonedDateTime zonedDT2
            = zonedDT.withLaterOffsetAtOverlap();
  
        // print ChronoZonedDateTime
        // after withLaterOffsetAtOverlap()
        System.out.println("After withLaterOffsetAtOverlap(): "
                           + zonedDT2);
    }
}

输出:

Before withLaterOffsetAtOverlap(): 2018-11-04T01:25:43-05:00[US/Central]
After withLaterOffsetAtOverlap(): 2018-11-04T01:25:43-06:00[US/Central]

程序2

// Java program to demonstrate
// ChronoZonedDateTime.withLaterOffsetAtOverlap() method
  
import java.time.*;
import java.time.chrono.*;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // create a ChronoZonedDateTime object
        ChronoZonedDateTime zonedDT
            = ZonedDateTime.of(
                LocalDateTime.of(2021, 11, 07, 1, 05, 53),
                ZoneId.of("US/Central"));
  
        // print ChronoZonedDateTime
        System.out.println("Before withLaterOffsetAtOverlap(): "
                           + zonedDT);
  
        // apply withLaterOffsetAtOverlap()
        ChronoZonedDateTime zonedDT2
            = zonedDT.withLaterOffsetAtOverlap();
  
        // print ChronoZonedDateTime
        // after withLaterOffsetAtOverlap()
        System.out.println("After withLaterOffsetAtOverlap(): "
                           + zonedDT2);
    }
}

输出:

Before withLaterOffsetAtOverlap(): 2021-11-07T01:05:53-05:00[US/Central]
After withLaterOffsetAtOverlap(): 2021-11-07T01:05:53-06:00[US/Central]

参考资料: https://docs.oracle.com/javase/9/docs/api/java/time/chrono/ChronoZonedDateTime.html#withLaterOffsetAtOverlap-

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程

Java ChronoZonedDateTime