【发布时间】:2012-03-05 23:44:34
【问题描述】:
我尝试 System.out 相同的字符串
System.out.println(" DATE 29 " + new Date(1330462800000l) + " Date 01 "
+ new Date(1330549200000l));
但是当我在构建中检查它(以控制台模式运行)和从 eclipse 运行应用程序时,我得到了不同的结果。
eclipse的输出(好像是正确的结果):
日期 2012 年 2 月 29 日星期三 00:00:00 EET 日期 01 星期四 3 月 1 日 00:00:00 EET 2012
构建输出(控制台模式)
日期 2012 年 2 月 28 日星期二 23:00:00 EET 日期 2 月 29 日星期三 23:00:00 EET 2012
很抱歉这个愚蠢的问题,但你对可能的原因有什么想法吗?
PS:我使用 maven+tycho 构建,打包类型的 eclipse-repository。(如果真的很重要)
编辑: 在 Eclipse 中,我查看了 timeZone 值:
Calendar calendar=Calendar.getInstance();
System.out.println("!!!time zone before: " + calendar.getTimeZone());
!!!之前的时区: sun.util.calendar.ZoneInfo[id="Europe/Minsk",offset=7200000,dstSavings=3600000,useDaylight=true,transitions=121,lastRule=java.util.SimpleTimeZone[id=Europe/Minsk,offset=7200000, dstSavings=3600000,useDaylight=true,startYear=0,startMode=2,startMonth=2,startDay=-1,startDayOfWeek=1,startTime=7200000,startTimeMode=1,endMode=2,endMonth=9,endDay=-1, endDayOfWeek=1,endTime=7200000,endTimeMode=1]]
然后我用硬编码的 zoneId 设置时区并进行构建
calendar.setTimeZone(TimeZone.getTimeZone("Europe/Minsk"));
没有任何结果
编辑:我在 build 和 eclipse 中使用了不同版本和架构的 jres。这可能是原因吗? 编辑:
System.out.println("!!!!!! system.timezone " + System.getProperty("user.timezone"));
System.setProperty("user.timezone", "Europe/Minsk");
System.out.println("!!!!!! system.timezone " + System.getProperty("user.timezone"));
!!!!!! system.timezone 欧洲/明斯克
!!!!!! system.timezone Europe/Minsk!!!区域后的日历时间: sun.util.calendar.ZoneInfo[id="Europe/Minsk",offset=7200000,dstSavings=3600000,useDaylight=true,transitions=121,lastRule=java.util.SimpleTimeZone[id=Europe/Minsk,offset=7200000, dstSavings=3600000,useDaylight=true,startYear=0,startMode=2,startMonth=2,startDay=-1,startDayOfWeek=1,startTime=7200000,startTimeMode=1,endMode=2,endMonth=9,endDay=-1, endDayOfWeek=1,endTime=7200000,endTimeMode=1]]
正确的时区。但是日期还是错了
【问题讨论】:
-
VM 运行环境中的时区设置。
-
抱歉,同一台机器可以不同吗?
-
是的,TZ 是进程环境的一部分,可以更改。虽然看起来“EET”可能是 TZ,而且两者都是一样的,所以可能是一个红鲱鱼。
-
您知道有一个历史视图可以查看对问题的编辑吗?您应该考虑将编辑内容合并到原始问题中以使其更具可读性
标签: date maven eclipse-plugin eclipse-rcp tycho