Java TimeZone - getOffset() Method
The java.util.TimeZone.getOffset() method is used to get the time zone offset, for current date, modified in case of daylight savings. This is the offset to add to UTC to get local time.
Syntax
public abstract int getOffset(int era, int year, int month, int day, int dayOfWeek, int milliseconds)
Parameters
era |
Specify the era of the given date. |
year |
Specify the year in the given date. |
month |
Specify the month in the given date. Month is 0-based. e.g., 0 for January. |
day |
Specify the day-in-month of the given date. |
dayOfWeek |
Specify the day-of-week of the given date. |
milliseconds |
Specify the milliseconds in day in standard local time. |
Return Value
Returns the offset in milliseconds to add to GMT to get local time.
Exception
NA
Example:
The example below shows how to use the java.util.TimeZone.getOffset() method.
import java.util.*; public class MyClass { public static void main(String[] args) { //creating a TimeZone object TimeZone tz = TimeZone.getTimeZone("IST"); //printing the offset value of the time zone System.out.println("Offset value: " + tz.getOffset(1, 2015, 1, 1, 1, 1000)); } }
The output of the above code will be:
Offset value: 19800000
❮ Java.util - TimeZone