Java SimpleTimeZone setRawOffset()方法及示例
SimpleTimeZone类 的 setRawOffset() 方法是用来设置基础时区与GMT的偏移。该偏移量被添加到UTC中以获得本地时间。
语法
public void setRawOffset(int offsetMillis)
参数: 该函数接受一个参数 offsetMillis ,指定给定的基础时区与GMT的偏移。
返回值: 该方法没有返回值。
异常: 该函数没有抛出任何异常。
下面的程序演示了上述函数。
程序1 :
// program to demonstrate the// function java.util.SimpleTimeZone.setRawOffset()import java.util.*;public class GFG { public static void main(String[] args) { // create simple time zone object SimpleTimeZone obj = new SimpleTimeZone(500, "GMT"); // printing RawOffset value System.out.println("Initially RawOffset is = " + obj.getRawOffset()); // setting RawOffset on object obj obj.setRawOffset(6000000); System.out.println("RawOffset " + "set to 6000000"); // printing RawOffset value System.out.println("Current RawOffset is = " + obj.getRawOffset()); }}
输出
Initially RawOffset is = 500
RawOffset set to 6000000
Current RawOffset is = 6000000
程序2
// program to demonstrate the// function java.util.SimpleTimeZone.setRawOffset()import java.util.*;public class GFG { public static void main(String[] args) { // create simple time zone object SimpleTimeZone obj = new SimpleTimeZone(800, "GMT"); // printing RawOffset value System.out.println("Initially RawOffset is = " + obj.getRawOffset()); // setting RawOffset on object obj obj.setRawOffset(8000000); System.out.println("RawOffset " + "set to 8000000"); // printing RawOffset value System.out.println("Current RawOffset is = " + obj.getRawOffset()); }}
输出
Initially RawOffset is = 800
RawOffset set to 8000000
Current RawOffset is = 8000000