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