Timezone freakiness
Just solved a mind-boggling problem I was having with some date manipulation.
The Date constructor returns a date with a different timezone depending on whether the date is today & before, or in the future.
var today:Date = new Date();
var yesterday:Date = new Date( today.fullYear, today.month, today.date - 1 );
var today2:Date = new Date( today.fullYear, today.month, today.date );
var tomorrow:Date = new Date( today.fullYear, today.month, today.date + 1 );
trace( yesterday.timezoneOffset );
trace( today2.timezoneOffset );
trace( tomorrow.timezoneOffset );
Traces output:
300
300
240
What's worse if you then subtract a day from "tomorrow" it doesn't equal today.
tomorrow.date--;
trace( tomorrow.time == today.time );
trace( tomorrow == today );
Output: false / false
Guess why?
Today's daylight savings switchover day. Arghhh.
I really wish Actionscript had a date-only type.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home