得到GMT时间

本来以为得到GMT时间很简单,通过Calendar 
date = Calendar.getInstance(TimeZone.getTimeZone(”GMT”));然后
date.getTime()就是,但是实际的结果不是,要得到GMT时间还是需要转换下的,以下是得到当前的GMT时间:
    public static Date getGMTDate ()
    {
        Calendar calendar = Calendar.getInstance();
        int offset = calendar.get(Calendar.ZONE_OFFSET)/3600000 +
               
calendar.get(Calendar.DST_OFFSET)/3600000;
        calendar.add(Calendar.HOUR,-offset);
        return calendar.getTime();
    }


作者: Cherami
原载: 得到GMT时间
版权所有。转载时必须以链接形式注明作者和原始出处及本声明。

日志评价

 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 (暂无评价) --点击星星直接投票
Loading ... Loading ...


相关日志



随机日志



添加到网摘

[del.icio.us]  [新浪 VIVI]  [365key]  [YouNote]  [博采中心]  [Poco]  [SOHU狐摘]  [天极网摘]  [和讯网摘]
喜欢这个插件?

当前日志信息