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

获取Java时区的夏令时转换日期

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

获取Java时区的夏令时转换日期

由于该

DateTimeZone.nextTransition
方法,Joda
Time
(和以往一样)使此操作变得非常容易。例如:

import org.joda.time.*;import org.joda.time.format.*;public class Test{        public static void main(String[] args)    {        DateTimeZone zone = DateTimeZone.forID("Europe/London");     DateTimeFormatter format = DateTimeFormat.mediumDateTime();        long current = System.currentTimeMillis();        for (int i=0; i < 100; i++)        { long next = zone.nextTransition(current); if (current == next) {     break; } System.out.println (format.print(next) + " Into DST? "+ !zone.isStandardOffset(next)); current = next;        }    }}

输出:

25-Oct-2009 01:00:00进入DST?假28-Mar-2010 02:00:00进入DST?真正31-Oct-2010 01:00:00进入DST?假27-Mar-2011 02:00:00进入DST?真正30-Oct-2011 01:00:00进入DST?假25-Mar-2012 02:00:00进入DST?真正28-Oct-2012 01:00:00进入DST吗?假2013年3月31日02:00:00进入DST?真正2013年10月27日01:00:00进入DST?假2014年3月30日02:00:00进入DST?真正26-Oct-2014 01:00:00进入DST吗?假2015年3月29日02:00:00进入DST?真正25-Oct-2015 01:00:00进入DST吗?假...

使用Java
8,您可以通过

ZoneRules
nextTransition
previousTransition
方法获得相同的信息。



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

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

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