Java中的TimeZone类的getOffset()方法用于从UTC或世界标准时间获知该TimeZone在特定日期的偏移值。
用法:
public int getOffset(long in_date)
参数:该方法接受一个长类型的参数in_date,它表示格林尼治标准时间1970年1月1日00:00:00以来的实际日期(以毫秒为单位)。
返回值:该方法返回TimeZone的ID。
下面的程序演示了TimeZone的getOffset()方法的用法:
示例1:
// Java code to illustrate getOffset() method
import java.util.*;
public class TimeZoneDemo {
public static void main(String args[])
{
// Creating a TimeZone
TimeZone offtime_zone
= TimeZone.getTimeZone("Europe/Rome");
// Checking the offset for the systems date
System.out.println("The Offset Value is:"
+ offtime_zone
.getOffset(Calendar.ZONE_OFFSET));
}
}
输出:
The Offset Value is:3600000
示例2:
// Java code to illustrate getOffset() method
import java.util.*;
public class TimeZoneDemo {
public static void main(String args[])
{
// Creating a TimeZone
TimeZone offtime_zone
= TimeZone.getTimeZone("Pacific/Pago_Pago");
// Checking the offset for the systems date
System.out.println("The Offset Value is:"
+ offtime_zone
.getOffset(Calendar.ZONE_OFFSET));
}
}
输出:
The Offset Value is:-39600000