Skip to content
Related Articles

Related Articles

Improve Article

ZoneOffsetTransition getOffsetAfter() method in Java with Example

  • Last Updated : 05 Jun, 2020

The getOffsetAfter() method of java.time.zone.ZoneOffsetTransition class is used to get the offset value of second offset zone after transition has taken place. The first and second offset refers to the value passed while creating the ZoneOffsetTransition Object.

Syntax:

public ZoneOffset getOffsetAfter()

Parameter: This method does not accept any parameter.

Return Value: This method returns the offset value of the second zone offset after transition has taken place. It does not return Null.

Below are the examples to illustrate the getOffsetAfter() method:



Example 1:




// Java program to demonstrate
// getOffsetAfter() 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(
                8);
  
        // Creating and initializing the
        // object of ZoneOffset
        ZoneOffset off2
            = ZoneOffset.ofTotalSeconds(
                12);
  
        // Creating and initializing
        // ZoneOffsetTransition Object
        ZoneOffsetTransition zonetrans1
            = ZoneOffsetTransition.of(
                loc, off1, off2);
  
        // Getting the offset after value
        // by using getOffsetAfter() method
        ZoneOffset off
            = zonetrans1.getOffsetAfter();
  
        // Display the result
        System.out.println(
            "Zoneoffset after transition : "
            + off);
    }
}
Output:
Zoneoffset after transition : +00:00:12

Example 2:




// Java program to demonstrate
// getOffsetAfter() 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
        ZoneOffsetTransition zonetrans1
            = ZoneOffsetTransition.of(
                loc, off1, off2);
  
        // Getting the offset after value
        // by using getOffsetAfter() method
        ZoneOffset off
            = zonetrans1.getOffsetAfter();
  
        // Display the result
        System.out.println(
            "Zoneoffset after transition : "
            + off);
    }
}
Output:
Zoneoffset after transition : +00:00:08

Reference:https://docs.oracle.com/javase/9/docs/api/java/time/zone/ZoneOffsetTransition.html#getOffsetAfter–

Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.




My Personal Notes arrow_drop_up
Recommended Articles
Page :