This problem has also been encountered recently. The same time is calculated on a computer, but it takes 8 hours to change the computer.
Keyword: JVM 8-hour time difference
Change the time zone of a specific application without changing the Machine Time Zone (multiple methods ):
1,
Timezone TZ = timezone. gettimezone ("Asia/Shanghai ");
Timezone. setdefault (Tz );
2,
Java-duser. timezone = UTC timezonetip
Java-duser. timezone = Asia/Shanghai
3,
For tomcat, modify its Catalina. BAT to set java_opts =-duser. timezone = Asia/Shanghai
Add-duser. timezone = Asia/Shanghai.
4. Code
Date utildate = new java. util. Date ();
Simpledateformat myfmt = new simpledateformat ("yyyy-mm-dd hh: mm: SS ");
Timezone timezonechina = timezone. gettimezone ("Asia/Shanghai"); // obtain the China Time Zone
Myfmt. settimezone (timezonechina); // sets the system time zone
Return myfmt. Format (utildate );
This problem has also been encountered recently. The same time is calculated on a computer, but it takes 8 hours to change the computer.
Keyword: JVM 8-hour time difference
Change the time zone of a specific application without changing the Machine Time Zone (multiple methods ):
1,
Timezone TZ = timezone. gettimezone ("Asia/Shanghai ");
Timezone. setdefault (Tz );
2,
Java-duser. timezone = UTC timezonetip
Java-duser. timezone = Asia/Shanghai
3,
For tomcat, modify its Catalina. BAT to set java_opts =-duser. timezone = Asia/Shanghai
Add-duser. timezone = Asia/Shanghai.
4. Code
Date utildate = new java. util. Date ();
Simpledateformat myfmt = new simpledateformat ("yyyy-mm-dd hh: mm: SS ");
Timezone timezonechina = timezone. gettimezone ("Asia/Shanghai"); // obtain the China Time Zone
Myfmt. settimezone (timezonechina); // sets the system time zone
Return myfmt. Format (utildate );