码迷,mamicode.com
首页 > 其他好文 > 详细

日志时间晚13小时

时间:2014-06-21 19:46:24      阅读:258      评论:0      收藏:0      [点我收藏+]

标签:java timezone

  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.


本文出自 “Ying:好记性不如烂笔头” 博客,请务必保留此出处http://yingtju.blog.51cto.com/3760152/1429180

日志时间晚13小时,布布扣,bubuko.com

日志时间晚13小时

标签:java timezone

原文地址:http://yingtju.blog.51cto.com/3760152/1429180

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!