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

本文介绍了Java中的TimeZone类的getOffset()方法,该方法用于获取指定日期时TimeZone相对于UTC的偏移值。通过示例代码展示了如何使用getOffset()方法,分别演示了在"Europe/Rome"和"Pacific/Pago_Pago"时区的偏移情况。输出显示了这两个时区相对于UTC的时间差。
摘要由CSDN通过智能技术生成

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值