Java new Date () Incorrect current time

When I do this:

new Date();

      

The year, day, and other things are all right, but the hour and minute are wrong. I am using 64-bit Windows 7 on 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 the date object in Java (I am using Java 1.6) the zone id is America / Caracas, which should be Europe / Istanbul

What could be the problem, any ideas?

PS: I don't want to pass the timezone as a VM parameter, I don't want to use the Calendar object. I have several libraries that use Date object instead of anything, I just want to look into the problem .

+3


source to share


2 answers


I think this blog can help you.

Quoting from a blog post to solve the problem:

After opening the date and time dialog from the Windows XP Control Panel and applying one of the following changes, the Java API starts working properly:

  • Changing the date / time manually and then returning to the original correct time.
  • Change the time zone and then return to the original.
  • Request to automatically update the time from the time server.


For posts and the same blog:

Further research showed that:

  • People are complaining about wrong timezone problems in Sun Java VM with JRE 1.3. Several bug reports have been reported against the Sun Java Virtual Machine over the past ten years about the default timezone being incorrect.
  • Almost all of the reports were rejected by Sun as unreproducible.
+3


source


You can use Calendar:

Calendar.getInstance(TimeZone.getTimeZone("GMT"), locale);

      



Dates are "locale dependent". You can also install Locale:

Locale.setDefault(...);

      

+3


source







All Articles