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.