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