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 / August 2007

Tip: Looking for answers? Try searching our database.

Java Time/Calendar Bug?

Thread view: 
Hal Vaughan - 08 Aug 2007 02:27 GMT
I have the following in my code:

GregorianCalendar cal = new GregorianCalendar();
...
tString = "00" + String.valueOf(cal.get(Calendar.HOUR_OF_DAY));

When I run it, now, the time is one hour behind my system's time.  I've been
searching, but it seems the closest bug I could find was effecting Palm
Pilots.  I'm using a program composed on Java 1.4.2 and running on Java 5.
If the time zone matters, I'm on Eastern Time, during Daylight Savings.
This is happening now, but could have been an issue previously and I may
not have noticed it.

I've also replaced HOUR_OF_DAY with HOUR and had the same problem.

I know the US has decided to muck things up and start DST earlier and end it
later and I see how that would effect this issue during the "exception"
days effected by that change, but I wouldn't expect it to effect the time
during September, when we're normally in DST>\.

Does anyone have more info about this?

Hal
Knute Johnson - 08 Aug 2007 02:51 GMT
> I have the following in my code:
>
[quoted text clipped - 19 lines]
>
> Hal

Hal:

You running Linux?  Maybe Fedora?

Signature

Knute Johnson
email s/nospam/knute/

Hal Vaughan - 08 Aug 2007 05:21 GMT
>> I have the following in my code:
>>
[quoted text clipped - 24 lines]
>
> You running Linux?  Maybe Fedora?

Yes, Linux.  Ubuntu Feisty on this system.

Hal
Knute Johnson - 08 Aug 2007 05:44 GMT
>>> I have the following in my code:
>>>
[quoted text clipped - 27 lines]
>
> Hal

There is a bug, I can't find my notes right now to tell you what the
number is but the fix is to remove any spaces from your timezone in
/etc/sysconfig/clock.  Mine was:

ZONE=America/Los Angeles and I changed it to

ZONE=America/Los_Angeles

That solved my one hour problem with Java.  Now I'm not sure that Ubuntu
uses /etc/sysconfig/clock.  I don't have any Ubuntu running here but I
will load the live CD after I post this and see what I can find.

Signature

Knute Johnson
email s/nospam/knute/

Hal Vaughan - 08 Aug 2007 06:08 GMT
>>>> I have the following in my code:
>>>>
[quoted text clipped - 39 lines]
> uses /etc/sysconfig/clock.  I don't have any Ubuntu running here but I
> will load the live CD after I post this and see what I can find.

Do you know if there's any side effects with other Linux programs, or do
they recognize the underscore and space as the same in time zones?

If it's just on my system, that's no problem.  I'm testing it on my
computer.  Most people running this will be on Windows.  A few will be on
Linux, but they're smart enough they can work with me on this.

Thanks for the info -- I was wondering if I was doing something wrong!

Hal
Knute Johnson - 08 Aug 2007 06:49 GMT
>>>>> I have the following in my code:
>>>>>
[quoted text clipped - 41 lines]
> Do you know if there's any side effects with other Linux programs, or do
> they recognize the underscore and space as the same in time zones?

As far as I know it does not affect any other programs (he says).

> If it's just on my system, that's no problem.  I'm testing it on my
> computer.  Most people running this will be on Windows.  A few will be on
> Linux, but they're smart enough they can work with me on this.

Windows shouldn't be a problem.

> Thanks for the info -- I was wondering if I was doing something wrong!
>
> Hal

I just loaded up my Ubuntu CD and ran it live and I don't find a
/etc/sysconfig/clock.  In fact there is no sysconfig directory.  I'm not
sure where Ubuntu keeps the timezone.  You might look around for that.
On Fedora it is in the clock file.  I would be curious to know if you
find out where it is kept.

The bug number is 6456628.  Somebody posted the note here a couple of
months ago about the space versus under_score.  You might vote for this
bug if you have any to spare.

What time zone are you in Hal?

Signature

Knute Johnson
email s/nospam/knute/

Ingo Menger - 08 Aug 2007 14:41 GMT
> >>>> I have the following in my code:
>
[quoted text clipped - 42 lines]
> Do you know if there's any side effects with other Linux programs, or do
> they recognize the underscore and space as the same in time zones?

You can most easily test this by running
   date
   perl -e '$x= localtime(time); print "$x";'
etc.
On some *Xs, there is a environment variable TZ, that works like this
(all commands typed within a few minutes):

$ echo $TZ
MET
$ date
Wed Aug  8 15:32:35 MEST 2007
$ TZ=XXX date
Wed Aug  8 13:32:46 GMT 2007
$ TZ=UTC+5 date
Wed Aug  8 08:33:05 UTC 2007
$ TZ=UTC-5 date
Wed Aug  8 18:33:13 UTC 2007
$ TZ=EST date
Wed Aug  8 08:33:28 EST 2007
$ TZ=EST+1 date
Wed Aug  8 12:34:00 EST 2007
$ TZ=XXX+1 date
Wed Aug  8 12:34:34 XXX 2007

On that system, TZ is honored and there is a set of known timezones
(i.e. MET where it also knows the associated daylight savings timezone
name or EST (that is the same as 5 hours west UTC) and you can also
enter a custom timezone where the time zone name is not honored, thus
EST+1 is the same as XXX+1 and is interpreted as UTC+1)

> If it's just on my system, that's no problem.  I'm testing it on my
> computer.  Most people running this will be on Windows.  A few will be on
> Linux, but they're smart enough they can work with me on this.

As long as the programs I listed above print the same time as your
program does, then it is okay. Otherwise, it's a problem with java or
your program.
Roedy Green - 09 Aug 2007 07:25 GMT
On Tue, 07 Aug 2007 21:27:42 -0400, Hal Vaughan
<hal@thresholddigital.com> wrote, quoted or indirectly quoted someone
who said :

>When I run it, now, the time is one hour behind my system's time.

I have written a little tool for helping resolve these problems.
See http://mindprod.com/jgloss/timezone.html

It shows you the default TimeZone, the current time and whether DST is
in effect. It also shows you all the TimeZones supported in your Java.
Signature

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.