Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / July 2007

Tip: Looking for answers? Try searching our database.

Timezone problem in Fedora Linux

Thread view: 
Knute Johnson - 06 Jun 2007 06:29 GMT
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...
Gordon Beaton - 06 Jun 2007 08:44 GMT
> 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

--
Knute Johnson - 08 Jun 2007 00:13 GMT
>> 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
[quoted text clipped - 8 lines]
>
> /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/
Gordon Beaton - 08 Jun 2007 08:11 GMT
> 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

--
Roedy Green - 15 Jun 2007 11:11 GMT
>I would expect the timezone seen by the browser, and hence the applet,
>to follow the same rules.

Perhaps the browser has its own TZ setting.  Use Wassup to see what
system properties the browser is using.

see http://mindprod.com/applets/wassup.html
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
Knute Johnson - 17 Jun 2007 23:40 GMT
>> I would expect the timezone seen by the browser, and hence the applet,
>> to follow the same rules.
[quoted text clipped - 4 lines]
> see http://mindprod.com/applets/wassup.html
> --

The problem is the bug that Gordon identified.  I don't think it is
going to get fixed because there are only two votes for the bug.

knute...
kyleki@gmail.com - 07 Jul 2007 03:50 GMT
On Jun 7, 4:13 pm, Knute Johnson <nos...@rabbitbrush.frazmtn.com>
wrote:
> [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?
Roedy Green - 07 Jul 2007 07:20 GMT
>On my machine, I found that putting an underscore in the ZONE entry
>fixed the problem:
>ZONE="America/Los_Angeles"

see http://mindprod.com/jgloss/timezone.html for the official list of
Timezone names.  They never contain spaces. They always have
underscores.  I don't know though about names for DateFormat.parse.

--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
Knute Johnson - 12 Jul 2007 18:33 GMT
> On Jun 7, 4:13 pm, Knute Johnson <nos...@rabbitbrush.frazmtn.com>
> wrote:
[quoted text clipped - 8 lines]
> 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.

Signature

Knute Johnson
email s/nospam/knute/

Roedy Green - 15 Jun 2007 11:10 GMT
On Tue, 05 Jun 2007 22:29:01 -0700, Knute Johnson
<nospam@rabbitbrush.frazmtn.com> wrote, quoted or indirectly quoted
someone who said :

>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?

see http://mindprod.com/jgloss/timezone.html

Make sure your OS timezone and time are properly configured. Also turn
on DST.

--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.