当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Java ZonedDateTime withLaterOffsetAtOverlap()用法及代码示例


ZonedDateTime类的withLaterOffsetAtOverlap()方法用于在将区域偏移更改为在本地时间线重叠处的两个有效偏移中的较晚位置之后,返回此ZonedDateTime对象的副本。当夏时制结束并且将一小时返回到时间线时,就会发生重叠。因此,本地日期时间有两个有效的偏移量,调用withLaterOffsetAtOverlap方法将返回ZonedDateTime和两个区域中的较晚一个。如果在不重叠的情况下调用此方法,则将返回此方法。此实例是不可变的,不受此方法调用的影响。

用法:

public ZonedDateTime withLaterOffsetAtOverlap()

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


返回值:此方法基于此日期时间(带有更高的偏移量)返回ZonedDateTime。

以下示例程序旨在说明withLaterOffsetAtOverlap()方法:

示例1:

// Java program to demonstrate 
// ZonedDateTime.withLaterOffsetAtOverlap() method 
  
import java.time.*; 
  
public class GFG { 
    public static void main(String[] args) 
    { 
  
        // create a ZonedDateTime object 
        ZonedDateTime zonedDT 
            = ZonedDateTime.of( 
                LocalDateTime.of(2018, 11, 4, 1, 25, 43), 
                ZoneId.of("US/Central")); 
  
        // print ZonedDateTime 
        System.out.println("Before withLaterOffsetAtOverlap(): "
                           + zonedDT); 
  
        // apply withLaterOffsetAtOverlap() 
        ZonedDateTime zonedDT2 
            = zonedDT.withLaterOffsetAtOverlap(); 
  
        // print ZonedDateTime 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 
// ZonedDateTime.withLaterOffsetAtOverlap() method 
  
import java.time.*; 
  
public class GFG { 
    public static void main(String[] args) 
    { 
  
        // create a ZonedDateTime object 
        ZonedDateTime zonedDT 
            = ZonedDateTime.of( 
                LocalDateTime.of(2021, 11, 07, 1, 05, 53), 
                ZoneId.of("US/Central")); 
  
        // print ZonedDateTime 
        System.out.println("Before withLaterOffsetAtOverlap(): "
                           + zonedDT); 
  
        // apply withLaterOffsetAtOverlap() 
        ZonedDateTime zonedDT2 
            = zonedDT.withLaterOffsetAtOverlap(); 
  
        // print ZonedDateTime 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/10/docs/api/java/time/ZonedDateTime.html#withLaterOffsetAtOverlap()



相关用法


注:本文由纯净天空筛选整理自AmanSingh2210大神的英文原创作品 ZonedDateTime withLaterOffsetAtOverlap() method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。