Java中TimeZone类的setRawOffset(int offsetMillis)方法用于将基本时区偏移量设置为GMT。此偏移值可以是UTC以获取本地时间。
用法:
public abstract void setRawOffset(int offsetMillis)
参数:该方法接受整数类型的单个参数offsetMillis,该参数指定给定的基准时区与GMT的偏移量。
返回值:该方法不返回任何值。
以下示例程序旨在说明上述函数:
示例1:
// Program to demonstrate the
// setRawOffset()
import java.util.*;
public class GFG {
public static void main(String[] args)
{
// Create time zone object
TimeZone obj
= TimeZone.getTimeZone("Pacific/Pago_Pago");
// 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 = -39600000 RawOffset set to 6000000 Current RawOffset is = 6000000
示例2:
// Program to demonstrate the
// setRawOffset()
import java.util.*;
public class GFG {
public static void main(String[] args)
{
// Create time zone object
TimeZone obj
= TimeZone.getTimeZone("Europe/Rome");
// 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 = 3600000 RawOffset set to 8000000 Current RawOffset is = 8000000
参考:https://docs.oracle.com/javase/7/docs/api/java/util/TimeZone.html#setRawOffset(int)
相关用法
- Java SimpleTimeZone setRawOffset()用法及代码示例
- Java TimeZone getDSTSavings()用法及代码示例
- Java TimeZone getID()用法及代码示例
- Java TimeZone getRawOffset()用法及代码示例
- Java TimeZone getOffset()用法及代码示例
- Java TimeZone getDisplayName()用法及代码示例
- Java TimeZone useDaylightTime()用法及代码示例
- Java TimeZone getOffset(int, int, int, int, int, int)用法及代码示例
- Java TimeZone getDefault()用法及代码示例
- Java TimeZone getTimeZone()用法及代码示例
- Java TimeZone hasSameRules()用法及代码示例
- Java TimeZone clone()用法及代码示例
- Java TimeZone setDefault()用法及代码示例
- Java TimeZone observesDaylightTime()用法及代码示例
- Java TimeZone inDaylightTime()用法及代码示例
注:本文由纯净天空筛选整理自Chinmoy Lenka大神的英文原创作品 TimeZone setRawOffset() Method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。