Java Utility Library

Java TimeZone - getOffset() Method



The java.util.TimeZone.getOffset() method returns the offset of this time zone from UTC at the specified date. If Daylight Saving Time is in effect at the specified date, the offset value is adjusted with the amount of daylight saving.

Syntax

public int getOffset(long date)

Parameters

date Specify the date represented in milliseconds since January 1, 1970 00:00:00 GMT.

Return Value

Returns the amount of time in milliseconds to add to UTC to get local time.

Exception

NA

Example:

In the example below, the java.util.TimeZone.getOffset() method is used to get offset of 'IST' time zone from UTC at the specified date.

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
    //from UTC at January 1, 1970 00:00:00 GMT
    System.out.println("Offset value: " + tz.getOffset(0));
  }
}

The output of the above code will be:

Offset value: 19800000

❮ Java.util - TimeZone