Inconsistent Java time

Source: Internet
Author: User

1.new date () What time is it? 8 hours difference from system

2.eclipse Console printing time differs from system by 8 hours

3.LOG4J log time differs from the system by 8 hours

The above question is actually the same problem.

Cause: The time zone that Java obtains is not the same as the system's time zone

Here's how to fix it:

1. Add the following sentence in front of the code: Timezone.setdefault (Timezone.gettimezone ("Asia/shanghai"))

2. Modify the set java_opts of the Catalina.bat file in Tomcat and add the-duser.timezone=gmt+08

3. Modify the default time zone in the registry change to (gmt+08:00) Beijing, Chongqing, Hong Kong, Urumqi

If you don't see it: Export the Hkey_local_machine\software\microsoft\windowsnt\currentversion\time Zones item from a normal machine with the same system and import it into your own machine.

Inconsistent Java time

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.