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("Inittally 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());
}
}
输出:
Inittally 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("Inittally 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());
}
}
输出:
Inittally RawOffset is = 800 RawOffset set to 8000000 Current RawOffset is = 8000000
相关用法
- Java TimeZone setRawOffset()用法及代码示例
- Java SimpleTimeZone equals()用法及代码示例
- Java SimpleTimeZone getOffset()用法及代码示例
- Java SimpleTimeZone getDSTSavings()用法及代码示例
- Java SimpleTimeZone clone()用法及代码示例
- Java SimpleTimeZone hasSameRules()用法及代码示例
- Java SimpleTimeZone setStartRule(int, int, int)用法及代码示例
- Java SimpleTimeZone setEndRule(int, int, int)用法及代码示例
- Java SimpleTimeZone setDSTSavings()用法及代码示例
- Java SimpleTimeZone toString()用法及代码示例
- Java SimpleTimeZone inDaylightTime()用法及代码示例
- Java SimpleTimeZone getRawOffset()用法及代码示例
- Java SimpleTimeZone hashCode()用法及代码示例
- Java SimpleTimeZone setStartYear()用法及代码示例
- Java SimpleTimeZone useDaylightTime()用法及代码示例
注:本文由纯净天空筛选整理自Twinkl Bajaj大神的英文原创作品 SimpleTimeZone setRawOffset() method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。