Java acquisition time and system time difference 8 hours the ultimate solution __java

Source: Internet
Author: User
Tags local time set time

First, the problem description: MyEclipse directly using the BEA\JDK142_04 JVM environment, the project log is always played 8 hours slower than the system time, and then directly using System.out.println (new Java.util.Date ()); It really is 8 hours slower than the system in the lower right corner.

Second, the problem-solving solution:

1. Set time zone---before taking the date >>>

TimeZone TZ = Timezone.gettimezone ("etc/gmt-8");
Timezone.setdefault (TZ);

This method is suitable for a single rapid acquisition of system local time

2. Set java command Parameters

Java-duser.timezone=asia/jerusalem datetest

3, set the default time zone for the JVM is East eight (Beijing time)--->>>

in the following four directories (BEA\JDK142_11\JRE\LIB\ZI\ETC, Bea\jdk142_11\jre\lib\zi, bea\jrockit81sp6_142_10\jre\lib\zi\etc, Bea\jrockit81sp6_142_10\jre\lib\zi) find GMT file Bak backup, Then duplicate a copy of GMT-8 and rename it to GMT, copy it, rerun the Java program problem to solve.

Related Article

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.