|
www.brianziman.com
Linux – Java – Web – Questions Answered, Problems Solved
| |
|
Brian Ziman about contact terms of use privacy policy activity site map |
Wrong Default TimeZone in Java on Red Hat Linux (Friday, June 20, 2008)While I have the fortune of running Ubuntu and Debian at home, I have the misfortune of working with Red Hat (Fedora Core 9, specifically) at the office. Today, I spent the afternoon fighting Java, which insisted that the time was an hour earlier than reality. I found a solution. So here's the environment. My computer lives in Eastern Daylight Time (UTC-04:00 at this time of year). Obviously, when Daylight Saving Time is not in effect, we're five hours behind UTC. My system is "properly" configured, with the time zone set to "America/New_York". My test program looks like this:
As you can see, it reports the non-DST version, because it's really just guessing. And it is also off by an hour. After reviewing a ton of literature and discussion online, the most commonly accepted work-around for this issue is to specify the TZ environment variable, which should be totally unnecessary. But it works:
But I was not satisfied by this... if the OS is properly configured, and Java is anything better than brain-dead, it should work. So I pulled out my trusty "strace" tool, for following system calls. You have to remember to use the "-f" parameter, so that it actually digs down into the useful child processes that get spawned.
What I ended up finding was that it was trying to open the file
I have to wonder if this only shows up for people with a space in their time zone name, like America/Los_Angeles and America/New_York. If that's the case, making that symbolic link might be the best solution for you, as it doesn't rely on system configuration. I hope this is useful for other folks, so they don't have to bash their heads against the wall for hours like I have. Good luck! CommentsThank you for documenting this. I'm running Fedora 9 in the "New York" zone and the symlink trick worked for me. -- (7/9/2008 3:58 PM)
Same problem and same solution for the Los Angeles time zone. Thanks for the fix. -- (8/27/2008 6:43 PM)
I had the same issue in FC9 since I am also in the America/New_York timezone. My fix was to edit /etc/sysconfig/clock since strace showed me it that syscalls originating from Java were reading that file. Turns out that it was the source of "America/New York". I updated the ZONE variable in the file as follows: -- Jeff Metcalf (9/12/2008 12:19 PM)
Good detective work guys! I ran into this same problem today, and you saved me some troubleshooting to figure out what was going on. I've reported this as a bug to the Fedora team: -- Kartik Subbarao (3/10/2009 3:36 PM)
Jeff's workaround, changing /etc/localtime is probably better than my approach of creating symlinks, though the symlink approach won't break whenever Redhat fixes their system, which can't be guaranteed for the localtime change... -- Brian (6/17/2009 10:41 PM)
|
|
All material copyright © 1995-2010 by
Brian Ziman, unless otherwise noted.
| |