Solve the problem that JDK is used in win7 with a time difference of 8 hours.

Source: Internet
Author: User
Tags time zones

As the saying goes, there is a single disaster. Just solved the problem of slow database connection and encountered the problem of time mismatch. Windows 7 is installed on your testing machine. During the test, it is found that the time difference is always 8 hours. Immediately think of the time zone is wrong, view the time zone settings in the control panel (by the way, BS win7, the control panel can not learn XP has a classic mode? If the time zone is correct, it does not seem to be a problem with the time zone settings.

Use the second solution. Download jdk1.5 and eclipse in win7 to output the system time zone and time. The output time zone is GMT. The time difference is 8 hours. It indicates that jdk1.5 cannot obtain the correct time zone in win7. In order to verify my hypothesis, the latest jdk1.6 is added, and the output is normal.

After the problem is found, we need to solve it. Why can't the time zone be obtained in XP and in win7? Search and find Sun mentioned this bug, and published a tzupdater. Download, run, and try again according to instructions. Is it my English usage instructions incorrect -_-! I will post the Updater address. If any of you can use it to send a response, I will ask you. Http://java.sun.com/javase/tzupdater_README.html)

Although it was not successful to use Updater, some things were found through his instructions. There is a tzmappings file in the/jdk1.5.0 _ 04/JRE/lib directory. Open it in notepad and record the time zones of all regions in the format of "China Standard Time:-: Asia/Shanghai:". It is naturally associated with the Registry. Therefore, open the node [HKEY_LOCAL_MACHINE/software/Microsoft/Windows NT/CurrentVersion/Time Zones/China Standard Time] of the Registry time zone. There is a key value that seems familiar to me, "mapid =-". Isn't that the value recorded in the tzmappings file. Let's look at other time zones, which are the same as the values in that file. Will Java be the time zone obtained through this key value? Open the same node in the Registry under win7. The surprise is that there is no mapid key in it. Compared with XP, mapid and index keys are missing, mui_display, mui_dlt, and mui_std are missing, otherwise, add the mapid key. Then, run the test program that took the system time. OK! Solve the problem!

Well, it seems that this is the reason. Let alone export all registry Time Zone nodes from XP. For the sake of insurance, only the mapid key is retained, and then all nodes are poured into the win7 Registry. In this way, jdk1.5 read time is complete!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.