日誌時間晚13小時

  1. 問題

OS:CentOS6.3

jdk:jdk6

文件創建時間正常,日誌記錄時間晚於系統時間13小時


2. 查看

$ locale
LANG=en_US
LC_CTYPE="en_US"
LC_NUMERIC="en_US"
LC_TIME="en_US"
LC_COLLATE="en_US"
LC_MONETARY="en_US"
LC_MESSAGES="en_US"
LC_PAPER="en_US"
LC_NAME="en_US"
LC_ADDRESS="en_US"
LC_TELEPHONE="en_US"
LC_MEASUREMENT="en_US"
LC_IDENTIFICATION="en_US"
LC_ALL=


$ more /etc/sysconfig/clock
ZONE="Asia/Shanghai"
UTC=false
ARC=false


3. 解決

java啓動參數加入-Duser.timezone="Asia/Shanghai"


4. 系統的默認user.timezone

When you say "defaults read from the OS & local system", there isn't a single, well-defined place to read this default from.  Even the API documentation itself says

Gets the default TimeZone for this host. The source of the default TimeZone may vary with implementation.

So the simple answer is that Joda and your JVM are inferring the default time zone from different sources of information.  The point to remember about this is that the default is a guess, not something that the JVM can definitively get access to.

For Sun's 1.5.0_06 JVM on Linux, the following order is used:

  1. Looks to environment variable TZ

  2. Looks for the file /etc/sysconfig/clock and tries to find the "ZONE" entry.

  3. Compares contents fo /etc/localtime with the contents of every file in /usr/share/zoneinfo recursively. When the contents matches, it returns the path and filename, referenced from /usr/share/zoneinfo.

Joda 1.6.2 uses:

  1. The system property user.timezone.

  2. If the above is null or not a valid identifier, the value of the JDK's TimeZone default is used.

  3. If that fails, UTC is used.


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章