EST时间与夏令时的转换

EST time conversion with daylight saving time

EST 夏令时转换错误

private void timeConversion() {
    String s = "2016-08-29 1:40:00 AM";
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss a", Locale.ENGLISH);
    df.setTimeZone(TimeZone.getTimeZone("EST"));
    Date timestamp = null;
    try {
        timestamp = df.parse(s);
        df.setTimeZone(TimeZone.getDefault());
        System.out.println(df.format(timestamp));
    } catch (ParseException e) {
        e.printStackTrace();

    }
}

时区 EST 不考虑任何夏令时偏移:

TimeZone estTz = TimeZone.getTimeZone("EST");
System.out.println(estTz.useDaylightTime()); // prints 'false'

即 EST 时区与 UTC 的时差始终为 -5:00。

这可能是由于加拿大、墨西哥和中美洲(巴拿马)的一些地方不使用夏令时,而是全年使用美国东部标准时间。

如果你想要一个带有 DST 偏移的时区,你应该使用类似 US/Eastern 或 America/New_York 等的东西:

TimeZone usEasternTz = TimeZone.getTimeZone("US/Eastern");
System.out.println(usEasternTz.useDaylightTime()); // prints 'true'