Issues to get end DayLight Saving time
I am trying check the DayLight Saving Time, for that I am using the US TimeZone. As DST start for US on 10 March 2013 at 2:00AM and will end on 3 November 2013 at 2:00AM. So we have to forward the clock 1 hour at 2:00AM and when it end then have to back the clock 1 hour at 2:00AM. I just wanted to check how time will be the actual time at 2:00AM when DST end. It is working fine for start of DST but for end of DST its not working. Here is the sample of code that I have tried:
TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles"));
Calendar cal =Calendar.getInstance();
if (TimeZone.getDefault().useDaylightTime())
{
for(int i = 0; i< 5 ; ++i)
{
cal.set(2013,10,03,1,57+i,60);
long timemillis = cal.getTimeInMillis();
setCurrentTimeInMills(timemillis);
String formatTime = Dateformated(timemillis);
System.out.println(formatTime);
}
}
Output is like:
03-11-2013 01:58:00 PST
03-11-2013 01:59:00 PST
03-11-2013 02:00:00 PST
03-11-2013 02:01:00 PST
03-11-2013 02:02:00 PST
My Java Version :1.6.0_16. Here Datformated() is user-define function to view the time in readable format and setCurrentTime() is also user-define method to set the current time.Can Anyone help me in that why at 1:59:60AM time become 2:00AM As best of my knowledge It should be 1:00AM instead?
The code below shows the timezone change from PDT to PST
public static void main(String[] args) throws InterruptedException {
TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles"));
DateFormat fmt = new SimpleDateFormat("dd-MM-yy HH:mm:ss zz");
Calendar cal = Calendar.getInstance();
cal.set(2013, 10, 03, 0, 59, 59);
System.out.println(fmt.format(cal.getTime()));
cal.set(2013, 10, 03, 1, 0, 0);
System.out.println(fmt.format(cal.getTime()));
}
outputs:
03-11-13 00:59:59 PDT
03-11-13 01:00:00 PST
链接地址: http://www.djcxy.com/p/29392.html
上一篇: 夏令时开始时间无效
下一篇: DayLight节省时间的问题