TimeZone getOffset(int, int, int, int, int, int) Method in Java with Examples
The getOffset(int era, int yr, int mon, int day, int dayOfWeek, int millisec) method of TimeZone class in Java is used to know the offset value of this TimeZone at a specific date or modified date in case of daylight savings, from the UTC or the Universal Time Coordinated. This offset value can be added to get the local time.
Syntax:
public abstract int
getOffset(int era, int yr,
int mon, int day,
int dayOfWeek, int millisec)
Parameters: The method can take the below mentioned parameters.
- era: This is of integer type and refers to the era of the given date.
- yr: This is of integer type and refers to the year in the given date.
- month: This is of integer type and refers to the month in the given date.
- day: This is of integer type and refers to the day-in-month of the given date.
- dayOfWeek: This is of integer type and refers to the day-of-week of the given date.
- milliseconds: This is of integer type and refers to the milliseconds in day in standard local time.
Return Value: The method returns the offset value in milliseconds that can be added to GMT to get local time.
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( 1, 2018, 5, 12, 2, 500)); } } |
The Offset Value is:7200000
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( 1, 1995, 9, 20, 2, 700)); } } |
The Offset Value is:-39600000
Recommended Posts:
- TimeZone getRawOffset() Method in Java with Examples
- TimeZone observesDaylightTime() method in Java with Examples
- TimeZone setID() Method in Java with Examples
- TimeZone setRawOffset() Method in Java with Examples
- TimeZone setDefault() Method in Java with Examples
- TimeZone useDaylightTime() method in Java with Examples
- TimeZone hasSameRules() Method in Java with Examples
- TimeZone getID() Method in Java with Examples
- TimeZone getOffset() Method in Java with Examples
- TimeZone getDSTSavings() Method in Java with Examples
- TimeZone getTimeZone() Method in Java with Examples
- TimeZone getDefault() Method in Java with Examples
- TimeZone getAvailableIDs() Method in Java with Examples
- TimeZone clone() Method in Java with Examples
- TimeZone getDisplayName() 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.



