我尝试 System.out 相同的字符串
System.out.println(" DATE 29 " + new Date(1330462800000l) + " Date 01 "
+ new Date(1330549200000l));
但是当我在 Build 中检查它(以控制台模式运行)和从 Eclipse 运行应用程序时,我得到了不同的结果。
eclipse的输出(似乎是正确的结果):
日期 2012 年 2 月 29 日星期三 00:00:00 EET 日期 2012 年 3 月 1 日星期四 3 月 1 日 00:00:00 EET
构建的输出(控制台模式)
日期 2012 年 2 月 28 日星期二 23:00:00 EET 日期 2012 年 2 月 29 日星期三 23:00:00 EET 日期 01
对不起,愚蠢的问题,但你对可能的原因有什么想法吗?
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]]
正确的时区。但日期仍然是错误的