Open In App

OffsetDateTime getOffset() method in Java with examples

Last Updated : 19 Sep, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report
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
// 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
// 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

Next Article

Similar Reads