ChronoZonedDateTime接口的withEarlierOffsetAtOverlap()方法用于在将区域偏移量更改为本地时间线重叠处的两个有效偏移量中的较早位置之后,返回此ChronoZonedDateTime对象的副本。当夏时制结束并且将一小时返回到时间线时,就会发生重叠。因此,本地日期时间有两个有效的偏移量,调用withEarlierOffsetAtOverlap方法将返回带有两个区域中较早时间的ChronoZonedDateTime。如果在不重叠的情况下调用此方法,则将返回此方法。此实例是不可变的,不受此方法调用的影响。
用法:
ChronoZonedDateTime withEarlierOffsetAtOverlap()
参数:此方法不接受任何参数。
返回值:此方法基于此日期时间返回ChronoZonedDateTime,并带有较早的偏移量。
以下示例程序旨在说明withEarlierOffsetAtOverlap()方法:
示例1:
// Java program to demonstrate
// withEarlierOffsetAtOverlap() method
import java.time.*;
import java.time.chrono.*;
public class GFG {
public static void main(String[] args)
{
// create a ChronoZonedDateTime object
ChronoZonedDateTime zonedDT
= ZonedDateTime
.ofLocal(
LocalDateTime.of(2018, 11, 4, 1, 25, 43),
ZoneId.of("US/Central"),
ZoneOffset.ofHours(-6));
// print ChronoZonedDateTime
System.out.println("Before"
+ " withEarlierOffsetAtOverlap():\n "
+ zonedDT);
// apply withEarlierOffsetAtOverlap()
ChronoZonedDateTime zonedDT2
= zonedDT.withEarlierOffsetAtOverlap();
// print ChronoZonedDateTime after
// withEarlierOffsetAtOverlap()
System.out.println("\nAfter"
+ " withEarlierOffsetAtOverlap():\n "
+ zonedDT2);
}
}
输出:
Before withEarlierOffsetAtOverlap(): 2018-11-04T01:25:43-06:00[US/Central] After withEarlierOffsetAtOverlap(): 2018-11-04T01:25:43-05:00[US/Central]
示例2:
// Java program to demonstrate
// withEarlierOffsetAtOverlap() method
import java.time.*;
import java.time.chrono.*;
public class GFG {
public static void main(String[] args)
{
// create a ChronoZonedDateTime object
ChronoZonedDateTime zonedDT
= ZonedDateTime
.ofLocal(
LocalDateTime.of(2021, 11, 07, 1, 05, 53),
ZoneId.of("US/Central"),
ZoneOffset.ofHours(-6));
// print ChronoZonedDateTime
System.out.println("Before"
+ " withEarlierOffsetAtOverlap():\n "
+ zonedDT);
// apply withEarlierOffsetAtOverlap()
ChronoZonedDateTime zonedDT2
= zonedDT.withEarlierOffsetAtOverlap();
// print ChronoZonedDateTime after
// withEarlierOffsetAtOverlap()
System.out.println("\nAfter"
+ " withEarlierOffsetAtOverlap():\n "
+ zonedDT2);
}
}
输出:
Before withEarlierOffsetAtOverlap(): 2021-11-07T01:05:53-06:00[US/Central] After withEarlierOffsetAtOverlap(): 2021-11-07T01:05:53-05:00[US/Central]
相关用法
- Java ZonedDateTime withEarlierOffsetAtOverlap()用法及代码示例
- Java ChronoZonedDateTime from()用法及代码示例
- Java ChronoZonedDateTime get()用法及代码示例
- Java ChronoZonedDateTime until()用法及代码示例
- Java ChronoZonedDateTime toInstant()用法及代码示例
- Java ChronoZonedDateTime isAfter()用法及代码示例
- Java ChronoZonedDateTime toLocalDate()用法及代码示例
- Java ChronoZonedDateTime getChronology()用法及代码示例
- Java ChronoZonedDateTime range()用法及代码示例
- Java ChronoZonedDateTime toLocalTime()用法及代码示例
- Java ChronoZonedDateTime getOffset()用法及代码示例
- Java ChronoZonedDateTime getLong()用法及代码示例
- Java ChronoZonedDateTime isEqual()用法及代码示例
- Java ChronoZonedDateTime isBefore()用法及代码示例
- Java ChronoZonedDateTime getZone()用法及代码示例
注:本文由纯净天空筛选整理自ShubhamMaurya3大神的英文原创作品 ChronoZonedDateTime withEarlierOffsetAtOverlap() method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。