日期:2014-05-20  浏览次数:20821 次

关于GregorianCalendar时区的问题???
Java code
TimeZone estZone = TimeZone.getTimeZone("EST");
        SimpleDateFormat sdfEST = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        sdfEST.setTimeZone(estZone);
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeZone(estZone);
        calendar.setTime(sdfEST.parse("2010-10-11 12:13:14"));
        System.out.println(sdfEST.format(calendar.getTime()));
        
        Calendar cal = new GregorianCalendar();
        cal.set(Calendar.YEAR, calendar.get(Calendar.YEAR));
        cal.set(Calendar.MONTH, calendar.get(Calendar.MONTH));
        cal.set(Calendar.DAY_OF_MONTH, calendar.get(Calendar.DAY_OF_MONTH));
        cal.set(Calendar.HOUR, calendar.get(Calendar.HOUR));
        cal.set(Calendar.MINUTE, calendar.get(Calendar.MINUTE));
        cal.set(Calendar.SECOND, calendar.get(Calendar.SECOND));
        System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(cal.getTime()));

我想测试EST时区的时间设置到当前的默认时区(Asia/ShangHai)
我希望第一个时间打印出来是
2010-10-11 12:13:14
第二个是
2010-10-10 23:13:14
但打印出来的两个都是一样的2010-10-11 12:13:14

------解决方案--------------------
我是ubuntu + jdk7u1