Timezone problem in Fedora Linux

K

Knute Johnson

I'm having a problem with the time in Java. I running Fedora 7 and
Sun's JDK 1.6.0_01. The time is one hour early and the timezone shows
GMT-0800 when it should be -0700. Any ideas?

[root@localhost tzupdater-1.2.1-2007f]# cat test.java
import java.util.*;

public class test {
public static void main(String[] args) {
System.out.println(new Date());
}
}

[root@localhost tzupdater-1.2.1-2007f]# java test
Tue Jun 05 21:26:02 GMT-08:00 2007

Thanks,

knute...
 
G

Gordon Beaton

I'm having a problem with the time in Java. I running Fedora 7 and
Sun's JDK 1.6.0_01. The time is one hour early and the timezone
shows GMT-0800 when it should be -0700. Any ideas?

What does /etc/sysconfig/clock contain?
What does the "date" command show?
What about "echo $TZ"?

Try updating /etc/localtime, it should be a copy of one of the files
in /usr/share/zoneinfo.

/gordon

--
 
K

Knute Johnson

Gordon said:
What does /etc/sysconfig/clock contain?
What does the "date" command show?
What about "echo $TZ"?

Try updating /etc/localtime, it should be a copy of one of the files
in /usr/share/zoneinfo.

/gordon

Gordon:

Thanks for the reply. $TZ is not set currently but I did try setting it
to US/Pacific. This fixes the problem only for programs run in the
terminal. Applets still show the wrong time. I don't know where the
time zone would be set for an applet but I would have thought that it
came from the system time zone. How is the time zone propagated in Linux?

Below are the answers to your questions. The correct time was 16:??
hours. I tried setting /etc/localtime to /usr/share/zoneinfo/PST8PDT
and /usr/share/zoneinfo/America/Los_Angeles. Neither make a difference.

[knute@localhost ~]$ cat /etc/sysconfig/clock
# The ZONE parameter is only evaluated by system-config-date.
# The timezone of the system is defined by the contents of /etc/localtime.
ZONE="America/Los Angeles"
UTC=false
ARC=false
[knute@localhost ~]$ date
Thu Jun 7 16:04:43 PDT 2007
[knute@localhost ~]$ echo $TZ

[knute@localhost ~]$ cat test.java
import java.util.*;

public class test {
public static void main(String[] args) {
System.out.println(new Date());
System.out.println(TimeZone.getDefault().getID());
}
}
[knute@localhost ~]$ java test
Thu Jun 07 15:05:04 GMT-08:00 2007
GMT-08:00
[knute@localhost ~]$

Also if I set the timezone on the command line -

[knute@localhost ~]$ java -Duser.timezone=US/Pacific test
Thu Jun 07 16:11:26 PDT 2007
US/Pacific
[knute@localhost ~]$

it gives the correct time and zone.

Thanks very much,

knute
email s/knute/nospam/
 
G

Gordon Beaton

Thanks for the reply. $TZ is not set currently but I did try setting it
to US/Pacific. This fixes the problem only for programs run in the
terminal. Applets still show the wrong time. I don't know where the
time zone would be set for an applet but I would have thought that it
came from the system time zone. How is the time zone propagated in Linux?

If TZ is set, then that timezone is used. If you set (and export) TZ
high up in the process hierarchy (e.g. /etc/profile), then all of your
processes will see it. For processes without TZ, the timezone defined
by /etc/localtime is used.

I would expect the timezone seen by the browser, and hence the applet,
to follow the same rules.
Below are the answers to your questions. The correct time was 16:??
hours. I tried setting /etc/localtime to /usr/share/zoneinfo/PST8PDT
and /usr/share/zoneinfo/America/Los_Angeles. Neither make a difference.

I'd also recommend setting UTC=true in /etc/sysconfig/clock unless
this is a dual boot Linux-Windows machine. (UTC=false is a concession
to Windows, which insists on storing localtime in the HW clock).

This might offer more insight:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6456628

/gordon

--
 
K

kyleki

[knute@localhost ~]$ cat /etc/sysconfig/clock
# The ZONE parameter is only evaluated by system-config-date.
# The timezone of the system is defined by the contents of /etc/localtime.
ZONE="America/Los Angeles"
UTC=false
ARC=false

On my machine, I found that putting an underscore in the ZONE entry
fixed the problem:
ZONE="America/Los_Angeles"

Is this a bug with the program that writes out /etc/sysconfig/clock or
with the way java parses it?
 
K

Knute Johnson

[knute@localhost ~]$ cat /etc/sysconfig/clock
# The ZONE parameter is only evaluated by system-config-date.
# The timezone of the system is defined by the contents of /etc/localtime.
ZONE="America/Los Angeles"
UTC=false
ARC=false

On my machine, I found that putting an underscore in the ZONE entry
fixed the problem:
ZONE="America/Los_Angeles"

That solved my problem too. In fact I don't need the "s any more.
Is this a bug with the program that writes out /etc/sysconfig/clock or
with the way java parses it?

Different Linux use different methods for keeping track of the timezone.
I don't know for sure how Java determines the current timezone but in
Fedora 7 it seems to read the /etc/sysconfig/clock file. That file
doesn't exist in other Linux versions.

There is a Java bug on this subject, 6456628.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top