java.util.SimpleTimeZone.getOffset() Method

Advertisements


Description

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

Declaration

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

public int getOffset(long date)

Parameters

  • date--This is the time at which the time zone offset is found.

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.SimpleTimeZone.getOffset()

package com.tutorialspoint;

import java.util.*;

public class SimpleTimeZoneDemo {
   public static void main( String args[] ){
      // create simple time zone object 
      SimpleTimeZone stobj = new SimpleTimeZone(720,"US");
      
      // get offset
      int offset=stobj.getOffset(Calendar.ZONE_OFFSET); 
      
      // check offset value       
      System.out.println("Offset is : " + offset);
   }     
}

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

Offset is : 720



Advertisements
Advertisements