ZoneOffsetTransition of() method in Java with Example
The of() method of java.time.zone.ZoneOffsetTransition class is used to create the object of zone offset transition with the help of local date time, offset before and offset after.
Syntax:
public static ZoneOffsetTransition of(LocalDateTime transition,
ZoneOffset offsetBefore,
ZoneOffset offsetAfter)
Parameter: This method takes the following argument as a parameter.
- transition: object of local date time for which transition have to be created.
- offsetBefore: object of zone offset for initial transition.
- offsetAfter: object of zone offset for final transition.
Return Value: This method returns the object of zone offset transition with the help of local date time, offset before and offset after.
Below are the examples to illustrate the of() method:
Example 1:
Java
import java.util.*;
import java.io.*;
import java.time.*;
import java.time.chrono.*;
import java.time.zone.*;
public class GFG {
public static void main(String[] argv)
{
LocalDateTime loc
= LocalDateTime.of(
1999 , 04 , 25 ,
03 , 24 , 45 , 0 );
ZoneOffset off1
= ZoneOffset.ofTotalSeconds( 12 );
ZoneOffset off2
= ZoneOffset.ofTotalSeconds( 8 );
ZoneOffsetTransition zonetrans1
= ZoneOffsetTransition.of(
loc, off1, off2);
String str
= zonetrans1.toString();
System.out.println(
"zone offset transition : "
+ str);
}
}
|
Output:
zone offset transition : Transition[Overlap at 1999-04-25T03:24:45+00:00:12 to +00:00:08]
Example 2:
Java
import java.util.*;
import java.io.*;
import java.time.*;
import java.time.chrono.*;
import java.time.zone.*;
public class GFG {
public static void main(String[] argv)
{
LocalDateTime loc
= LocalDateTime.of(
2018 , 04 , 25 ,
03 , 24 , 45 , 0 );
ZoneOffset off1
= ZoneOffset.ofTotalSeconds( 12 );
ZoneOffset off2
= ZoneOffset.ofTotalSeconds( 8 );
ZoneOffsetTransition zonetrans1
= ZoneOffsetTransition.of(
loc, off1, off2);
String str = zonetrans1.toString();
System.out.println(
"zone offset transition : "
+ str);
}
}
|
Output:
zone offset transition : Transition[Overlap at 2018-04-25T03:24:45+00:00:12 to +00:00:08]
Reference: https://docs.oracle.com/javase/9/docs/api/java/time/zone/ZoneOffsetTransition.html#of-java.time.LocalDateTime-java.time.ZoneOffset-java.time.ZoneOffset-
Last Updated :
14 Aug, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...