开发者

Java date issues in linux

OK, very bizarre issue here, can't seem to find much on it searching through here or in google.

I have a bot running on an IRC channel. Initially, I run it from my home PC (Windows) and it worked with no issues. Now I have moved it to a VPS (Linux) and find that it's not reporting dates correctly.

The VPS has the date set correctly:

bot@vps:~/bot$ date
Fri Jun 24 13:05:23 WST 2011

The bot has two time functions, one simply returns the time and one is a reminder system. Both use System.currentTimeMillis(). Both report the time 开发者_如何学JAVAwrong;

[13:10:00] ( mynick) !time
[13:10:00] ( botnick) mynick: The time is now Thu Jun 23 21:10:00
                 GMT-08:00 2011

or:

[13:20:19] ( mynick) remind me in 1 minute test
[13:20:19] ( botnick) bmynick: Okay, I'll remind you about that on Thu Jun
                 23 21:21:19 GMT-08:00 2011

So it seems it's finding the system time as GMT-8, but I have no idea why? Any suggestions?

Edit: Forced the Java time zone and it now reports correctly, so it seems to be something to do with the JVM


The problem here is that the JVM is not successfully detecting your system timezone.

I have heard a little about this before, but thought they were all fixed. What java version are you using. There is a detailed explanation of this problem here.

To manually set the timezone you can try these options:

  1. Export TZ variable: export TZ="US/Eastern"
  2. TimeZone.setDefault(TimeZone.getTimeZone("US/Eastern"))
  3. java -Duser.timezone=US/Eastern CLASS_NAME
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜