Incorrect Date in Java
I use next code to print current time
Calendar cal = Calendar.getInstance();
System.out.println(cal.getTime());
I have Windows XP sp3 istalled. Current time in sy开发者_开发知识库stem tray is 14:30. But this code return 13:30
Why returned time is wrong?
The default time zone used by java is probably different than the one configured in your OS. call cal.getTimeZone() to check the time zone. You can also set it with cal.setTimeZone(..).
Maybe you have set an incorrect locale. You could also try to set the daylight saving time offset.
SimpleDateFormat df = new SimpleDateFormat();
df.setTimeZone(TimeZone.getTimeZone("GMT+3:00"));
Calendar cal = Calendar.getInstance();
System.out.println(df.format(cal.getTime()));
精彩评论