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 intial 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:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java program to demonstrate
// of() method
  
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)
    {
  
        // creating and initializing
        // the object of LocalDateTime
        LocalDateTime loc
            = LocalDateTime.of(
                1999, 04, 25,
                03, 24, 45, 0);
  
        // creating and initializing
        // the object of ZoneOffset
        ZoneOffset off1
            = ZoneOffset.ofTotalSeconds(12);
  
        // creating and initializing
        // the object of ZoneOffset
        ZoneOffset off2
            = ZoneOffset.ofTotalSeconds(8);
  
        // creating and initializing
        // ZoneOffsetTransition Object
        // by using of() method
        ZoneOffsetTransition zonetrans1
            = ZoneOffsetTransition.of(
                loc, off1, off2);
  
        // getting the string representation
        // of this object
        String str
            = zonetrans1.toString();
  
        // display the result
        System.out.println(
            "zone offset transition : "
            + str);
    }
}

chevron_right


Output:

zone offset transition : Transition[Overlap at 1999-04-25T03:24:45+00:00:12 to +00:00:08]

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java program to demonstrate
// of() method
  
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)
    {
  
        // creating and initializing
        // the object of LocalDateTime
        LocalDateTime loc
            = LocalDateTime.of(
                2018, 04, 25,
                03, 24, 45, 0);
  
        // creating and initializing
        // the object of ZoneOffset
        ZoneOffset off1
            = ZoneOffset.ofTotalSeconds(12);
  
        // creating and initializing
        // the object of ZoneOffset
        ZoneOffset off2
            = ZoneOffset.ofTotalSeconds(8);
  
        // creating and initializing
        // ZoneOffsetTransition Object
        // by using of() method
        ZoneOffsetTransition zonetrans1
            = ZoneOffsetTransition.of(
                loc, off1, off2);
  
        // getting the string representation
        // of this object
        String str = zonetrans1.toString();
  
        // display the result
        System.out.println(
            "zone offset transition : "
            + str);
    }
}

chevron_right


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-

Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.