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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。