Skip to content
Related Articles
Open in App
Not now

Related Articles

OffsetDateTime getOffset() method in Java with examples

Improve Article
Save Article
Like Article
  • Last Updated : 11 Dec, 2018
Improve Article
Save Article
Like Article

The getOffset() method of OffsetDateTime class in Java gets the zone offset, such as ‘+05:00’.

Syntax :

public ZoneOffset getOffset()

Parameter : This method accepts does not accepts any parameter.

Return Value: It returns the zone offset, not null.

Below programs illustrate the getOffset() method:

Program 1 :




// Java program to demonstrate the getOffset() method
  
import java.time.OffsetDateTime;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // parses a date
        OffsetDateTime date = OffsetDateTime.parse("2018-12-03T12:30:30+01:00");
  
        // Prints the offset of given date
        System.out.println("offset: " + date.getOffset());
    }
}

Output:

offset: +01:00

Program 2 :




// Java program to demonstrate the getOffset() method
  
import java.time.OffsetDateTime;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // parses a date
        OffsetDateTime date = OffsetDateTime.parse("2016-10-03T12:30:30+06:20");
  
        // Prints the offset of given date
        System.out.println("Offset: " + date.getOffset());
    }
}

Output:

Offset: +06:20

Reference: https://docs.oracle.com/javase/8/docs/api/java/time/OffsetDateTime.html#getOffset–


My Personal Notes arrow_drop_up
Like Article
Save Article
Related Articles

Start Your Coding Journey Now!