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()
相關用法
- Java ChronoZonedDateTime withLaterOffsetAtOverlap()用法及代碼示例
- Java ZonedDateTime until()用法及代碼示例
- Java ZonedDateTime with()用法及代碼示例
- Java ZonedDateTime get()用法及代碼示例
- Java ZonedDateTime plus()用法及代碼示例
- Java ZonedDateTime of()用法及代碼示例
- Java ZonedDateTime now()用法及代碼示例
- Java ZonedDateTime plusWeeks()用法及代碼示例
- Java ZonedDateTime toLocalDateTime()用法及代碼示例
- Java ZonedDateTime truncatedTo()用法及代碼示例
- Java ZonedDateTime query()用法及代碼示例
- Java ZonedDateTime withZoneSameInstant()用法及代碼示例
- Java ZonedDateTime withZoneSameLocal()用法及代碼示例
- Java ZonedDateTime withFixedOffsetZone()用法及代碼示例
- Java ZonedDateTime minusDays()用法及代碼示例
注:本文由純淨天空篩選整理自AmanSingh2210大神的英文原創作品 ZonedDateTime withLaterOffsetAtOverlap() method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。