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 / January 2006

Tip: Looking for answers? Try searching our database.

Handling of DST in java

Thread view: 
nag - 10 Jan 2006 11:30 GMT
Hi,
Does java handle DST automatically ?
I'm using java Gregorian calendar to get the time/date.  Does this
automatically give the local time/date iirrespective of DST or special
handling should be done ?
Thomas Weidenfeller - 10 Jan 2006 13:43 GMT
> Does java handle DST automatically ?
> I'm using java Gregorian calendar to get the time/date.  Does this
> automatically give the local time/date iirrespective of DST or special
> handling should be done ?

What do you really want to do? If you need to represent a point in time
internally in your application, then a calendar is a bad choice. Use a
Date() object, or the time (as a long, in milliseconds). Java keeps its
date/time in milliseconds since Jan .1st, 1970 00:00 GMT. Only when you
you do some I/O you should consider if you want to have GMT/UTC
date/time, or local time (with DST)

E.g. if you just need to print out some time, [Simple]DateFormat is
often a much better choice than a calendar. It takes the local time-zone
into account, and you an specify another zone. Time-zone information
contains DST information.

A calendar is useful for presenting(!) some point in time in, guess
what, calender format, and doing some calculations based on this
representation, but not more. The representations produced by
GregorianCalender are somewhat imprecise. E.g. GregorianCalendar doesn't
know about leap seconds.

GregorianCalender does take time-zone information (and thus DST, if
defined for a time-zone) into account. But if I remember correctly, does
so inconsistently. If I remember correctly, then it sometimes assumes a
change from/to DST happens at midnight local time, which is wrong for
several time-zones. GregorianCalender also has a problem with the times
which appear twice when the clock is turned back at the end of DST. You
can't specify if you want to have the A (DST) or B (standard) time when
you e.g. set the HOUR value, or when you move into that period with and
add().

Doing timekeeping with a calender is usually a bad idea in Java.

/Thomas
Signature

The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/

Roedy Green - 10 Jan 2006 18:27 GMT
>Does java handle DST automatically ?
>I'm using java Gregorian calendar to get the time/date.  Does this
>automatically give the local time/date iirrespective of DST or special
>handling should be done ?

Yes.  However, because the tables are so voluminous, and because
people think it fun to change the rules, as if they were ordering the
sun to change it rising time, Sun's tables will always be a little
off.

I think it is a nutty idea.  It creates two goofy anomalies each year
-- a missing hour and an hour lived twice. Leave the time alone and
just declare different summer and winter business hours.
Non-compliance would help spread rush hour.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Stefan Ram - 10 Jan 2006 18:44 GMT
>I think it is a nutty idea.  It creates two goofy anomalies each year
>-- a missing hour and an hour lived twice. Leave the time alone and
>just declare different summer and winter business hours.

 I agree. It just seems to be an attempt to show to power of
 the government, "look, we can change the run of the time!" or
 "Look, we can make completely idiotic rules, still you have to
 live by them."

 In 2005, US-president Bush signed a paper to extend DST by
 four weeks in the USA (starting in 2007), and to make life
 even more complicated by adding another rule modification ...

 There is an "international movement" against it, the German
 website is

http://www.initiative-sonnenzeit.de/
Roedy Green - 10 Jan 2006 20:13 GMT
>  I agree. It just seems to be an attempt to show to power of
>  the government, "look, we can change the run of the time!" or
>  "Look, we can make completely idiotic rules, still you have to
>  live by them."

Local time is a concept on its way out.  With netmeetings across the
globe, you have to arrange your meeting in some common global base
time, be it UTC , EST or head office time.  

Similarly for satellite broadcasts across time zones.

As travel speeds up, we may find even meetings between in and out of
towners arranged in some common base -- NOT local time.

When a politician meddles with the rules for time, it creates a
headache for anyone who has a payroll system, or anything that runs 24
hours.

I first became aware of the problem back in the 1970s. To my surprise,
"war time" as it was originally called was quite chaotically employed,
using an offset up to 5 hours, with every community separately making
up their own rules about when to kick in and out each year.

Railroads refused to play and published their schedules in standard
time. I suppose with computers they have now relented.

I like the idea of keeping correlation between time and position of
the Sun in the sky.  Pretending the sun in irrelevant to man's
activity is just arrogance. It enforces the idea that man is not an
animal with the same environmental limitations that face all animals.

Java wisely stores all dates in UTC and considers timezone merely a
display  quirk, not something inherent in the measurement.

Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Raymond DeCampo - 10 Jan 2006 20:36 GMT
>> I agree. It just seems to be an attempt to show to power of
>> the government, "look, we can change the run of the time!" or
[quoted text clipped - 29 lines]
> Java wisely stores all dates in UTC and considers timezone merely a
> display  quirk, not something inherent in the measurement.

The sun is in fact a prime motivator for daylight saving time.
Politicians are not simply meddling with time to display their power.
It has been shown that daylight saving time results in less energy
consumption.  I'll leave it as an exercise to the reader why that is a
good thing. :-)

Ray

Signature

This signature intentionally left blank.

Stefan Ram - 10 Jan 2006 22:14 GMT
>It has been shown that daylight saving time results in less
>energy consumption.

 "less" in relation to what?

 Leaving the time zone unmodified, but shifting the start and
 end time of work might have the same effect.
Raymond DeCampo - 11 Jan 2006 20:26 GMT
>>It has been shown that daylight saving time results in less
>>energy consumption.
>
>   "less" in relation to what?

I think that it is clear that the statement above compares daylight
saving time to the lack of daylight saving time.

>   Leaving the time zone unmodified, but shifting the start and
>   end time of work might have the same effect.

Perhaps, but that is not something the government can easily legislate
nor enforce.  (Do you really want the time police checking to see if you
are working an hour later?)  Changing the wall clock time is the easiest
way to get people to actually observe the change.

There is nothing sacred about the time zone.  It has always been under
the purview of government.  In China, there should be about five time
zones by geographical standards, but there is only one.  In the U.S.,
the Eastern time zone is about twice as big as it should be.

Ray
Signature

This signature intentionally left blank.

Stefan Ram - 11 Jan 2006 20:52 GMT
>Perhaps, but that is not something the government can easily
>legislate nor enforce. (Do you really want the time police
>checking to see if you are working an hour later?)

 Something like this is done here for the closing-time of
 stores. So, since the government already enforces
 opening-times and closing-times of stores, they could change
 these and they could change to times for schools, universities
 and their own agencies. Some other institutions then might
 follow.

>There is nothing sacred about the time zone.

 It is only that, given two time stamps of the legal time for
 a location in Germany, like

2005-07-10T21:38:10 and
1960-07-10T21:38:13

 it would be a typical programming task to write a routine
 that can calculate the difference between them in seconds.
 And this would be much more easy, without the need to have
 to find out all details of regulations for DST in Germany.

 After WWII, in Germany, there were several different zones
 controlled by different countries and some details for the DST
 differed between these zones. In one zone, there was a special
 DST with two hours added for the mid of summer. Then there are
 reports that there were years with DST even in winter. And so
 on.

 All these special regulations make it very difficult to
 write such a routine.

Raymond DeCampo - 11 Jan 2006 22:04 GMT
>>Perhaps, but that is not something the government can easily
>>legislate nor enforce. (Do you really want the time police
[quoted text clipped - 6 lines]
>   and their own agencies. Some other institutions then might
>   follow.

By "here", I assume you mean Germany, based on what you wrote below.
There are no such laws in the US with the exception of some states that
have "blue laws" that only apply on Sundays.

Your suggestion sounds like a nightmare where you never know what is
going to be available when.

>>There is nothing sacred about the time zone.
>
[quoted text clipped - 19 lines]
>   write such a routine.
>  

This is why any environment worth its salt has these routines available
in a standard library.  Asking people to forgo a substantial reduction
in energy use for the (supposed) convenience of computer programmers is
ridiculous.  Remember that computers are not an end unto themselves,
they are tools here to serve.

Ray
Signature

This signature intentionally left blank.

Oliver Wong - 11 Jan 2006 22:37 GMT
>>>It has been shown that daylight saving time results in less
>>>energy consumption.
[quoted text clipped - 3 lines]
> I think that it is clear that the statement above compares daylight saving
> time to the lack of daylight saving time.

   Why would DST result in energy savings? (Not rhetorical, I really don't
know)

   - Oliver
Raymond DeCampo - 12 Jan 2006 13:47 GMT
>>>>It has been shown that daylight saving time results in less
>>>>energy consumption.
[quoted text clipped - 6 lines]
>     Why would DST result in energy savings? (Not rhetorical, I really don't
> know)

What happens is that people use more lights, etc. at night than in the
morning.  So moving an hour of daylight from the morning to the evening
cuts down on energy use.  There are more details at

<http://www.energy.ca.gov/daylightsaving.html>

if you are interested.

Ray

Signature

This signature intentionally left blank.

Luc The Perverse - 10 Jan 2006 20:45 GMT
>>I think it is a nutty idea.  It creates two goofy anomalies each year
>>-- a missing hour and an hour lived twice. Leave the time alone and
[quoted text clipped - 13 lines]
>
> http://www.initiative-sonnenzeit.de/

I really don't think Bush gives a sh.t what his people think let alone
Germans.

--
LTP

:)
Eric Sosman - 10 Jan 2006 18:57 GMT
Roedy Green wrote On 01/10/06 13:27,:

>>Does java handle DST automatically ?
>>I'm using java Gregorian calendar to get the time/date.  Does this
[quoted text clipped - 10 lines]
> just declare different summer and winter business hours.
> Non-compliance would help spread rush hour.

   Why stop there?  Get rid of this silly business of
time zones and just run the entire world on UTC.  (That
way I'll have a good excuse for lying in bed until noon
and not returning there until tomorrow morning.)

   While we're at it, let's reform the calendar: Who
needs this arbitrary assortment of irregularly-sized
months, anyhow?  "Thirty days hath September / The Ides
come on the fifteenth day ..."  Bosh!  And look at all
the confusion it's caused, what with the Merkins and
Yoorops unable to tell whether 6/6 is June 6 or 6 June.
A simple day-of-year count of 1..365 (0..365 in Leap
Year) would do just fine.  Knowing that today is the
10th and Christmas is the 359th would make it much
easier to count those shopping days ...

   Come to think of it, who really needs a count of
years any more?  We'll just get all of civil society to
switch to counting milliseconds since, since, well I
guess we'll just call it Millisecond Zero.  "You are
charged with serving alcohol to a person under the age
of 568036800000, for which you could be sent to prison
for as long as 126230400000.  How do you plead?"  See
how much simpler things are when you don't need to
specify which of a multitude of confusing units is
meant?

   Roedy, I think you've got something -- and if you'll
let me smoke some, too, I won't rat to the narcs.

Signature

Eric.Sosman@sun.com

Roedy Green - 10 Jan 2006 20:16 GMT
>  Come to think of it, who really needs a count of
>years any more?

At some point that will have to happen. Years are a very earth-centric
measure, hardly suitable for a civilisation spanning many worlds.

If someone discovers time is quantised, perhaps we could use  time
quanta since the big bang, with the high and low order bits deleted.

But now there appears to be some doubt there was a big bang after all.
We will have to pick an arbitrary starting point, perhaps the adoption
of the new calendar.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Eric Sosman - 10 Jan 2006 20:27 GMT
Roedy Green wrote On 01/10/06 15:16,:

>> Come to think of it, who really needs a count of
>>years any more?
[quoted text clipped - 8 lines]
> We will have to pick an arbitrary starting point, perhaps the adoption
> of the new calendar.

   Don't invent Yet Another Zero; stick with existing precedent:

http://www3.sympatico.ca/n.rieck/docs/calendar_time_y2k_etc.html#nov-17-1858

Signature

Eric.Sosman@sun.com

Roedy Green - 10 Jan 2006 23:06 GMT
>    Don't invent Yet Another Zero; stick with existing precedent:

the old Julian astronomer's calendar epoch is  a good one. It does not
have religious connotations.

Another than might just evolve out of Java is millis since 1970 since
programmers learn it as a side effect of debugging date code.
These probably is a defacto one that all the satellite and
astronomical folk use for high precision work.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Roedy Green - 10 Jan 2006 20:20 GMT
>    Roedy, I think you've got something -- and if you'll
>let me smoke some, too, I won't rat to the narcs.

I consider that sort of crack unacceptably rude, though I notice
people using them quite casually without obvious malice.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Eric Sosman - 11 Jan 2006 18:14 GMT
Roedy Green wrote On 01/10/06 15:20,:

>>   Roedy, I think you've got something -- and if you'll
>>let me smoke some, too, I won't rat to the narcs.
>
>  
> I consider that sort of crack unacceptably rude, though I notice
> people using them quite casually without obvious malice.

   My tongue was quite firmly in my cheek, as I thought
would be clear from the rest of my message.  If the
resulting grimace offended you, I apologize.

   It's been observed more than once that although Usenet
is a good channel for words, it's a poor communicator of
"attitude."

Signature

Eric.Sosman@sun.com

Chris Uppal - 11 Jan 2006 18:36 GMT
>     My tongue was quite firmly in my cheek, as I thought
> would be clear from the rest of my message.

It was transparently clear.

   -- chris
Alex Buell - 11 Jan 2006 19:49 GMT
On Tue, 10 Jan 2006 20:20:47 GMT Roedy Green
<my_email_is_posted_on_my_website@munged.invalid> waved a wand and this
message magically appeared:

> >    Roedy, I think you've got something -- and if you'll
> >let me smoke some, too, I won't rat to the narcs.
>  
> I consider that sort of crack unacceptably rude, though I notice
> people using them quite casually without obvious malice.

What's the matter, someone take away your sense of humour?

Signature

http://www.munted.org.uk

Anyone that thinks an imaginary deity is going to protect them against
earthquakes and hurricanes needs psychiatric help.

Oliver Wong - 10 Jan 2006 21:31 GMT
>    Come to think of it, who really needs a count of
> years any more?  We'll just get all of civil society to
[quoted text clipped - 6 lines]
> specify which of a multitude of confusing units is
> meant?

   I think it would make more sense to make the "second" the basic unit of
time, just like the "meter" is the basic unit of length, or the "litre" is
the basic unit of volume. And so the judge would probably not say "under the
age of 568036800 seconds", but rather "under the age of 568 megaseconds".

   But then again, 568 megaseconds seems rather arbitrary, and would only
exist for historical reasons related to the drinking age previously being
based on the unit of year. So with these new units, probably for
convenience, the drinking age would be amended to 500 megaseconds, or 600
megaseconds or some other round number (500 Ms is approximately 15 years and
10 months, 600 Ms is approximately 19 years).

   For a sense of scale with respect to life expectancy, 80 years is about
2.5 gigaseconds.

   - Oliver
Chris Uppal - 11 Jan 2006 11:55 GMT
> > I think it is a nutty idea.  It creates two goofy anomalies each year
> > -- a missing hour and an hour lived twice. Leave the time alone and
[quoted text clipped - 3 lines]
>     Why stop there?  Get rid of this silly business of
> time zones and just run the entire world on UTC.

The reason for stopping there is that DST is an outdated hack that could easily
/be/ dropped, whereas any the other options you mention would require that real
people adapt to it (which ain't going to happen -- obviously).

OTOH, if you are genuinely want to see peoples' local intuitions about
times-of-day reflected in the clock, why don't we go back to the idea that the
length of an hour/minute/second is dependent on the length of the local
day/night (as used to be the case) ?  That, very people-centric, idea was
dropped several hundred years ago, but only because they didn't have the
technology.  Nor had they (I think) the sophistication to recognise that they
could use two clocks, one for scientific/global purposes (such as astronomy and
international trade) and another for local purposes.   We do now (for both).
So the hour from midnight to 1 AM in Aberdeen should be longer than the
corresponding hour in London (at this time of year -- the reverse in summer). I
admit that that would introduce some small problems (for instance the local
speed limit would change with the time of day ;-), but nothing that couldn't
easily be dealt with.

   -- chris
Roedy Green - 11 Jan 2006 22:06 GMT
On Wed, 11 Jan 2006 11:55:17 -0000, "Chris Uppal"
<chris.uppal@metagnostic.REMOVE-THIS.org> wrote, quoted or indirectly
quoted someone who said :

>speed limit would change

I wonder how soon it will be economical to replace all painted speed
limit signs with electronic ones that can be controlled to give
sensible numbers depending on visibility, slipperiness, nearby
accidents and simply to optimally regulate traffic flow to prevent
congestion.  You could also have a sign an freeway on ramp to let you
know when an open slot was coming, and to ramp up to speed to meet it,
or to just stay off the freeway for a while since adding more cars
would reduce the aggregate flow.

It blows my mind how people insist on driving the speed limit in the
slickest ice, on the first snow when people are caught without snow
tires, or in pea-soup fog. You sometimes get multiple car pileups as a
result.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

nag - 12 Jan 2006 10:08 GMT
Hi ,
Thanks very much.
This is right that JAVA gregorian calendar has got this bug. When DST occurs
in Iran ( time 23:59:59 -> 01:00:00) the calendar returns wrong time. But it
works  when DST occurs in Egypt ( time 23:59:59 -> 01:00:00).
> Hi,
> Does java handle DST automatically ?
> I'm using java Gregorian calendar to get the time/date.  Does this
> automatically give the local time/date iirrespective of DST or special
> handling should be done ?


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



©2008 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.