OffsetDateTime getOffset() method in Java with examples
Last Updated :
19 Sep, 2023
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 :
import java.time.OffsetDateTime;
public class GFG {
public static void main(String[] args)
{
OffsetDateTime date = OffsetDateTime.parse( "2018-12-03T12:30:30+01:00" );
System.out.println( "offset: " + date.getOffset());
}
}
|
Program 2 :
import java.time.OffsetDateTime;
public class GFG {
public static void main(String[] args)
{
OffsetDateTime date = OffsetDateTime.parse( "2016-10-03T12:30:30+06:20" );
System.out.println( "Offset: " + date.getOffset());
}
}
|
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...