java.util.TimeZone.getOffset() Method



Description

The getOffset(long date) method is used to get the offset of this time zone from UTC at the specified date.

Declaration

Following is the declaration for java.util.TimeZone.getOffset() method.

public int getOffset(long date)

Parameters

date − This is the date represented in milliseconds since January 1, 1970 00:00:00 GMT.

Return Value

The method call returns the amount of time in milliseconds to add to UTC to get local time.

Exception

NA

Example

The following example shows the usage of java.util.TimeZone.getOffset()

package com.tutorialspoint;

import java.util.*;

public class TimeZoneDemo {
   public static void main( String args[] ) {

      // create time zone object     
      TimeZone timezone = TimeZone.getTimeZone("Europe/Paris");

      // checking offset value for date      
      System.out.println("Offset value:" + 
      timezone.getOffset(Calendar.ZONE_OFFSET));
   }    
}

Let us compile and run the above program, this will produce the following result.

Offset value:3600000
java_util_timezone.htm
Advertisements