TimeZone

该博客为转载内容,转载自https://www.cnblogs.com/kapok/archive/2005/12/23/303155.html ,涉及Java相关知识。
1     TimeZone gmt = TimeZone.getTimeZone("GMT");
2 
3     Calendar epoch1900 = Calendar.getInstance(gmt);

可以解决我们的环境中各个服务器之间的时区不同步的问题。

 1     /**
 2      * Gets the <code>TimeZone</code> for the given ID.
 3      *
 4      * @param ID the ID for a <code>TimeZone</code>, either an abbreviation
 5      * such as "PST", a full name such as "America/Los_Angeles", or a custom
 6      * ID such as "GMT-8:00". Note that the support of abbreviations is
 7      * for JDK 1.1.x compatibility only and full names should be used.
 8      *
 9      * @return the specified <code>TimeZone</code>, or the GMT zone if the given ID
10      * cannot be understood.
11      */
12     public static synchronized TimeZone getTimeZone(String ID) {
13     return getTimeZone(ID, true);
14     }
15 
16     private static TimeZone getTimeZone(String ID, boolean fallback) {
17     TimeZone tz = ZoneInfo.getTimeZone(ID);
18     if (tz == null) {
19         tz = parseCustomTimeZone(ID);
20         if (tz == null && fallback) {
21         tz = new ZoneInfo(GMT_ID, 0);
22         }
23     }
24     return tz;
25     }

转载于:https://www.cnblogs.com/kapok/archive/2005/12/23/303155.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值