Saturday, October 25, 2025
HomeLanguagesJavaZoneOffsetTransition of() method in Java with Example

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




// 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- 

RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS