TimeZone setRawOffset() Method in Java with Examples
The setRawOffset(int offsetMillis) method of TimeZone class in Java is used to set the base time zone offset to GMT. This offset value can be to UTC to get the local time. Syntax:
public abstract void
setRawOffset(int offsetMillis)
Parameters: The method accepts a single parameter offsetMillis of Integer type which specifies the given base time zone offset to GMT. Return Value: The method does not return any value. Below program illustrates the above-mentioned function: Program 1:
Java
import java.util.*;
public class GFG {
public static void main(String[] args)
{
TimeZone obj
= TimeZone.getTimeZone("Pacific/Pago_Pago");
System.out.println("Initially RawOffset is = "
+ obj.getRawOffset());
obj.setRawOffset( 6000000 );
System.out.println("RawOffset "
+ "set to 6000000 ");
System.out.println("Current RawOffset is = "
+ obj.getRawOffset());
}
}
|
Output:
Initially RawOffset is = -39600000
RawOffset set to 6000000
Current RawOffset is = 6000000
Program 2:
Java
import java.util.*;
public class GFG {
public static void main(String[] args)
{
TimeZone obj
= TimeZone.getTimeZone("Europe/Rome");
System.out.println("Initially RawOffset is = "
+ obj.getRawOffset());
obj.setRawOffset( 8000000 );
System.out.println("RawOffset "
+ "set to 8000000 ");
System.out.println("Current RawOffset is = "
+ obj.getRawOffset());
}
}
|
Output:
Initially RawOffset is = 3600000
RawOffset set to 8000000
Current RawOffset is = 8000000
Reference: https://docs.oracle.com/javase/7/docs/api/java/util/TimeZone.html#setRawOffset(int)
Last Updated :
05 Dec, 2022
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...