200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > java date timezoneoffset_Java TimeZone getOffset()用法及代码示例

java date timezoneoffset_Java TimeZone getOffset()用法及代码示例

时间:2022-09-06 15:46:24

相关推荐

java date timezoneoffset_Java TimeZone getOffset()用法及代码示例

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

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。