tags:

views:

39

answers:

2

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 system tray is 14:30. But this code return 13:30

Why returned time is wrong?

+1  A: 

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(..).

Eyal Schneider
I changed TimeZone. But result not changed. Any other ideas?
Polaris
@polaris: Did you remember to re-set the current time (with setTime) after changing the timezone?
Eyal Schneider
A: 

Maybe you have set an incorrect locale. You could also try to set the daylight saving time offset.

Ham
I check locale of OS. Everything is right. Do you mean to set offset in code?
Polaris