AS3: quick hint – Converting int to date

Ok, this just drove me nuts for a few minutes..

I’m getting the server time UNIX formatted, I was constantly trying to convert the integer to a readable date, constantly getting the wrong year (the default or zero unix year is 1970) but aren’t we living in 2009?

So for future reference and for anyone that might be searching for this.

Unix time is seconds based, Flash time is milliseconds based. got it?
So anytime you get a unix time integer you just need to multiply by 1000 to get the correct time for your Flash project.

Example:

GOOD CODE

curDate                = new Date(Number(dateXML.int * 1000));

BAD CODE

curDate                = new Date(Number(dateXML.int));
Leave a comment

0 Comments.

Leave a Reply


[ Ctrl + Enter ]