栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何将本地日期转换为格林尼治标准时间

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何将本地日期转换为格林尼治标准时间

这个怎么样 -

public static void main(String[] args) throws IOException {    Test test=new Test();    Date fromDate = Calendar.getInstance().getTime();    System.out.println("UTC Time - "+fromDate);    System.out.println("GMT Time - "+test.cvtToGmt(fromDate));}private  Date cvtToGmt( Date date ){    TimeZone tz = TimeZone.getDefault();    Date ret = new Date( date.getTime() - tz.getRawOffset() );    // if we are now in DST, back off by the delta.  Note that we are checking the GMT date, this is the KEY.    if ( tz.inDaylightTime( ret )){        Date dstDate = new Date( ret.getTime() - tz.getDSTSavings() );        // check to make sure we have not crossed back into standard time        // this happens when we are on the cusp of DST (7pm the day before the change for PDT)        if ( tz.inDaylightTime( dstDate )){ ret = dstDate;        }     }     return ret;}

测试结果
UTC时间-5月15日星期二16:24:14 IST 2012
GMT时间-5月15日星期二10:54:14 IST 2012



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/496925.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号