Writing in AS3. I cannot write:
t:Date = u.data.time;
u.data.time
is "Mon Oct 31 00:0开发者_运维百科0:00 GMT-0500 2005"
,because this cannot convert to Date.
Can you guys suggest a way to assign this to a date?
You should be able to use Date.parse(), like so:
var t : Date = new Date( Date.parse(u.data.time) );
The static Date.parse()
method returns, according to the documentation, "a number equaling the number of milliseconds elapsed since January 1, 1970, UTC", which incidentally is the same time format that the Date()
constructor expects as it's first parameter, when no other parameters are given.
EDIT: After OP stating that the above code doesn't work, I have tried the following example, which works fine for me:
var str : String = 'Mon Oct 31 00:00:00 GMT-0500 2005';
var t : Number = Date.parse(str);
var d : Date = new Date(t);
trace(t); // Outputs: 1130734800000
trace(d.toString()); // Outputs: Mon Oct 31 06:00:00 GMT+0100 2005
Although it's printed in my local timezone, the Date
instance d
seems to include the correct date/time data.
精彩评论