问题描述
CalendarcurrentTime=Calendar.getInstance(TimeZone.getTimeZone("GMT"));CalendardefaultTime=Calendar.getInstance();System.out.println(currentTime);System.out.println(defaultTime);System.out.println(currentTime.getTimeInMillis());System.out.println(defaultTime.getTimeInMillis());output:java.util.GregorianCalendar[time=1301642733907,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="GMT",offset=0,dstSavings=0,useDaylight=false,transitions=0,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2011,MONTH=3,WEEK_OF_YEAR=14,WEEK_OF_MONTH=1,DAY_OF_MONTH=1,DAY_OF_YEAR=91,DAY_OF_WEEK=6,DAY_OF_WEEK_IN_MONTH=1,AM_PM=0,HOUR=7,HOUR_OF_DAY=7,MINUTE=25,SECOND=33,MILLISECOND=907,ZONE_OFFSET=0,DST_OFFSET=0]java.util.GregorianCalendar[time=1301642733907,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="Asia/Shanghai",offset=28800000,dstSavings=0,useDaylight=false,transitions=19,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2011,MONTH=3,WEEK_OF_YEAR=14,WEEK_OF_MONTH=1,DAY_OF_MONTH=1,DAY_OF_YEAR=91,DAY_OF_WEEK=6,DAY_OF_WEEK_IN_MONTH=1,AM_PM=1,HOUR=3,HOUR_OF_DAY=15,MINUTE=25,SECOND=33,MILLISECOND=907,ZONE_OFFSET=28800000,DST_OFFSET=0]13016427339071301642733907我都问下这两个Calendarobject有什么区别?从结果看一样的哟,从打出的毫秒数是一样的,依我直观的想法,GMT时区应该比默认的少8小时哟,但是实际结果却不是这样的,不理解TimeZone了?有理解的指教下.
解决方案
解决方案二:
CalendardefaultTime=Calendar.getInstance();这个返回的是相对于用户所在时区的GWT时间,所以用它获得的时间跟系统时间查8小时。