[thelist] Daylight saving time + javascript

Luther, Ron Ron.Luther at hp.com
Fri Nov 15 09:35:01 CST 2002


Hi Stevenson,

I'd rather do this in a server-side language since I think it
would be more "dependable" because : (a) you would have control
over the system clock as opposed to hitting the users PC with
JS, and (b) you wouldn't have to worry about folks hitting the
page with JS turned off.


But JS does have a date object. You can invoke this by setting a
variable:

var MyToday = new Date()

Once you have that you can find the month and date within the month
by invoking the appropriate methods:

MyMonth = MyToday.getMonth()
[January = 0, value runs 0 to 11]

MyDay = MyToday.getDate()
[value runs from 1 to 31]

MyDOW = MyToday.getDay()
[value runs from 0 to 6, where 0 is Sunday]

Now you can test for 2nd Sundays and last Sundays and all that
other fun stuff that goes into daylight savings time computations.

I'd point out that daylight savings time can be a very tricky thing
if you have users surfing in from many different locations around the
world (or even around the US).  You might want to have some kind of
note on your page indicating that you are talking about daylight
savings time for a specific city or town.

HTH,


RonL.


-----Original Message-----
From: Stevenson Ngila [mailto:Stevenson at epr.footman-walker.com]

Am doing a project that entails determining whether the current date is in
the daylight saving time that falls between first sunday of April and Last
sunday of October.

Can anybody give me ideas as to how i can do this?



More information about the thelist mailing list