I think Bart's suggestion is a good one. I suspect the problem may be a
local time zone offset issue. The Date object stores a date value as an
integer representing the number of milliseconds since the Epoch
(midnight Jan 1, 1970 UTC). If you don't use UTC dates rigorously, you
leave yourself open to the vagaries of time zone offset problems.
In other words, the time zone setting on your computer matters when you
create a date object the way you described below. You can test this by
running the following code, then running it again after adjusting the
time zone setting on your computer:
// results from San Francisco
var checkin = new Date(2006,5,20);
trace(checkin);// Tue Jun 20 00:00:00 GMT-0700 2006
trace(checkin.getTime()); // 115078680
// results when Time zone is set to London
trace(checkin);// Tue Jun 20 00:00:00 GMT+0100 2006
trace(checkin.getTime()); // 115075800
Notice that you actually get different millisecond values. Also notice
that the London local time version of new Date(2006,5,20) will always be
interpreted as June 19 in the US because if it's midnight in London,
it's always the day before here in the US.
The best way to avoid this problem is to always work with UTC dates. Try
the same test above, using the Date.UTC() method, and you'll find that
the millisecond value is the same no matter which time zone setting you
use:
var checkinUTC = new Date(Date.UTC(2006,5,20));
trace(checkinUTC); // [June 20, 2006 in your local time]
trace(checkinUTC.getTime()); // 115076160
Just be sure to always use the UTC versions of the Date class methods
and properties, or you'll experience the same problem:
trace(checkinUTC.getUTCFullYear()); // 2006
trace(checkinUTC.getUTCMonth());// 5
trace(checkinUTC.getUTCDate()); // 20
HTH,
Francis
-Original Message-
From: [EMAIL PROTECTED] [mailto:flashcoders-
[EMAIL PROTECTED] On Behalf Of Bart Wttewaall
Sent: Tuesday, May 02, 2006 5:15 PM
To: Flashcoders mailing list
Subject: Re: [Flashcoders] Date Object Problem
I'm not sure if it'll solve your problem, but you might want to check
out Date.UTC
var maryBirthday_date:Date = new Date(Date.UTC(1974, 7, 12));
trace(maryBirthday_date);
I'm not sure what it does (something with universal time), since the
documentation is quite cryptic, but perhaps it's related..?
Good luck.
2006/5/2, Nick McNeill [EMAIL PROTECTED]:
First off, long-time member of this list and have gained a wealth of
knowledge from the wisdom here. Thank You All.
I'm having a very confusing problem using the Date Object. I have a
hotel reservation system built in flash, when an international
reservation (outside of the US, mainly Europe ) comes through, the
dates are off by 1 day. I cannot recreate the problem using any
system setup in the US, only via a friend in London doing some
testing for me.
Problem:
create new Date using May 20th 2006
var checkin = new Date(2006,5,20);
is getting converted to May 19th if you are in Europe, fine in the
US.
In plain terms, someone is trying to book 5/20/06 thru 5/22/2006,
but
gets booked 5/19/06 thru 5/21/06 instead.
This system has booked literally thousands of domestic US
reservations and we've never seen this until we opened it up to
international customers.
Any insight to why this could be happening, or any known workarounds
for a problem like this would be wonderful. I haven't tried using
the
timezone offset yet, any ideas if that might be a cure?
Nick McNeill
Intellistrand
843-839-1480
___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com
___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com
___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com