Reputation: 75257
When I do:
new Date();
Year, day and other things are OK but hour and minute is wrong. I use 64 bit Windows 7 at my computer and:
Windows time is OK,
Bios Time is OK,
Windows Time Zone is OK,
Windows Time Zone at Regedit is OK
However when I check date object at Java (I use Java 1.6) id of zone info is America/Caracas which should be Europe/Istanbul
What can be the problem, any ideas?
PS: I don't want to pass time zone as VM parameter, I don't want to use a Calendar object cos I have some libraries that uses Date object instead of anything, I just want to learn the problem.
Upvotes: 3
Views: 8016
Reputation: 28746
I think this blog can help you.
Quote from the blog post to solve the issue:
After opening the date/time dialog from the Windows XP Control Panel, and applying one of following changes, Java API starts working correcty:
- Changing date/time manually and then changing back to original correct time.
- Changing timezone and then back to original one.
- Requesting automatic time update from time server.
For the records and from the same blog:
Some further investigation revealed that:
- People complain about wrong timezone issues on Sun Java Virtual Machine since JRE 1.3. Several bug reports were submitted against Sun Java Virtual Machine during last ten years about wrong default timezone.
- Nearly all reports were rejected by Sun as unreproducible.
Upvotes: 3
Reputation: 64
You can use a Calendar :
Calendar.getInstance(TimeZone.getTimeZone("GMT"), locale);
Dates are "Locale dependant". You can set the Locale too :
Locale.setDefault(...);
Upvotes: 3