TimeZone getOffset() Method in Java with Examples
The getOffset() method of TimeZone class in Java is used to know the offset value of this TimeZone at a specific date from the UTC or the Universal Time Coordinated.
Syntax:
public int getOffset(long in_date)
Parameters: The method accepts one parameter, in_date of long type that refers to the actual date represented in milli-seconds since 1st January 1970 at 00:00:00 GMT.
Return Value: The method returns the ID of the TimeZone.
Below programs illustrate the working of getOffset() Method of TimeZone:
Example 1:
// Java code to illustrate getOffset() method import java.util.*; public class TimeZoneDemo { public static void main(String args[]) { // Creating a TimeZone TimeZone offtime_zone = TimeZone.getTimeZone("Europe/Rome"); // Checking the offset for the systems date System.out.println("The Offset Value is:" + offtime_zone .getOffset(Calendar.ZONE_OFFSET)); } } |
The Offset Value is:3600000
Example 2:
// Java code to illustrate getOffset() method import java.util.*; public class TimeZoneDemo { public static void main(String args[]) { // Creating a TimeZone TimeZone offtime_zone = TimeZone.getTimeZone("Pacific/Pago_Pago"); // Checking the offset for the systems date System.out.println("The Offset Value is:" + offtime_zone .getOffset(Calendar.ZONE_OFFSET)); } } |
The Offset Value is:-39600000
Reference: https://docs.oracle.com/javase/7/docs/api/java/util/TimeZone.html#getOffset()
Recommended Posts:
- TimeZone getOffset(int, int, int, int, int, int) Method in Java with Examples
- OffsetTime getOffset() method in Java with examples
- OffsetDateTime getOffset() method in Java with examples
- SimpleTimeZone getOffset() method in Java with Examples
- ChronoZonedDateTime getOffset() method in Java with Examples
- TimeZone getID() Method in Java with Examples
- TimeZone setDefault() Method in Java with Examples
- TimeZone getRawOffset() Method in Java with Examples
- TimeZone useDaylightTime() method in Java with Examples
- TimeZone clone() Method in Java with Examples
- TimeZone setRawOffset() Method in Java with Examples
- TimeZone getDSTSavings() Method in Java with Examples
- TimeZone getAvailableIDs() Method in Java with Examples
- TimeZone setID() Method in Java with Examples
- TimeZone observesDaylightTime() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



