Open In App

ZoneOffsetTransition of() method in Java with Example

Last Updated : 14 Aug, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

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




// 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);
    }
}


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

Example 2: 

Java




// 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);
    }
}


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- 



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads