-
Bug
-
Resolution: Unresolved
-
P4
-
None
-
1.4.0, 1.4.1
-
Fix Understood
-
x86, sparc
-
linux, solaris_9, windows_2000
My java file:
import java.util.*;
public class calTest
{
public static void main(String argv[]) {
TimeZone tz = TimeZone.getTimeZone("GMT");
//my locate is Asia/Shanghai(GMT+8:00), so the following code set the cal to
//20030301T160000Z
Calendar cal = new GregorianCalendar(2003,2,2,0,0,0);
cal.setTimeZone(tz); //now the timezone change from Aisa/Shanghai to GMT
cal.set(Calendar.HOUR_OF_DAY,0); //in GMT, set the hour to 0
//so the cal should be now 20030301T000000Z
System.out.println( cal.get(Calendar.DAY_OF_MONTH) + "--" + cal.get(Calendar.HOUR_OF_DAY));
}
}
Expecting output:
1--0
Real output:
2--0
In fact, the cal now is 20030302T000000Z, but not 20030301T000000Z which is my expectation.
import java.util.*;
public class calTest
{
public static void main(String argv[]) {
TimeZone tz = TimeZone.getTimeZone("GMT");
//my locate is Asia/Shanghai(GMT+8:00), so the following code set the cal to
//20030301T160000Z
Calendar cal = new GregorianCalendar(2003,2,2,0,0,0);
cal.setTimeZone(tz); //now the timezone change from Aisa/Shanghai to GMT
cal.set(Calendar.HOUR_OF_DAY,0); //in GMT, set the hour to 0
//so the cal should be now 20030301T000000Z
System.out.println( cal.get(Calendar.DAY_OF_MONTH) + "--" + cal.get(Calendar.HOUR_OF_DAY));
}
}
Expecting output:
1--0
Real output:
2--0
In fact, the cal now is 20030302T000000Z, but not 20030301T000000Z which is my expectation.
- duplicates
-
JDK-4844441 In Calendar, the order of calls to setTimeZone() and setTime() affects getTime()
- Closed