Home >Java >javaTutorial >What should I do if the time obtained by Java is inconsistent with the system time?
Solutions to the inconsistency between the time obtained by java and the system time: 1. Add parameters when the JVM is running and specify the time zone; 2. Set the time zone directly in the program; 3. Add 28800 directly.
Solution to the inconsistency between the java acquisition time and the system time:
Method 1: Add parameters when the JVM is running, Specify time zone -D user.timezone=GMT 08
Method 2: Set the time zone directly in the program. System.setProperty(“user.timezone”,”GMT 08″);
Method 3: Just add 28800 directly (8hours*60min*60sec=28800)
Follow this ideas. Regarding the search-related steps, when tomcat starts, the way to set a default time zone is to add the following line of code in the catalina.sh file
JAVA_OPTS="$JAVA_OPTS -Dfile.encoding=UTF8 -Duser.timezone=GMT+08"
Restart tomcat and it will be normal.
Related learning recommendations: java basic tutorial
The above is the detailed content of What should I do if the time obtained by Java is inconsistent with the system time?. For more information, please follow other related articles on the PHP Chinese website!