如何在java中使用DST时区获得正确的时间(毫秒)

时间:2015-04-01 04:28:27

标签: java timezone dst

我的问题很简单:

TimeZone fromTimeZone = TimeZone.getTimeZone("America/Santiago");
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, 8);
calendar.set(Calendar.MINUTE, 45);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
System.out.println(calendar.getTime() + " |Mili: " + calendar.getTimeInMillis());

输出:(我的时区是ICT)

Wed Apr 01 19:45:00 ICT 2015 |Milisecond: 1427892300000

问题是:日历在DST日返回此时区的错误时间。时区“America / Santiago”现在应该是UTC-3(参考:http://www.timeanddate.com/worldclock/chile/santiago。)。它需要显示:

Wed Apr 01 18:45:00 ICT 2015 |Milisecond: 1427888700000

1 个答案:

答案 0 :(得分:0)

您尚未将时区fromTimeZone应用于日历。