22
Jan/10
2

Unix Timestamp in Flash

Recently i needed to convert normal Time to Unix Timestamp in Flash. I couldn't get how to go about it intially. But when i gone through the definition of Unix Timestamp, its was clear for me.

"The unix time stamp is a way to track time as a running total of seconds. This count starts at the Unix Epoch on January 1st, 1970. Therefore, the unix time stamp is merely the number of seconds between a particular date and the Unix Epoch."

In order to count the number of seconds till a time, we have method Date.getTime() in Flash. This will effectively return the number of seconds from the Unix Epoch till the Date.

This is how i tried to find out the number of seconds till today's System Time:

var myDate = new Date();
trace(myDate);
var unixTime = Math.round(myDate.getTime()/1000);
trace("Unix Time: "+unixTime);

Output:

Fri Jan 22 13:01:55 GMT+0530 2010
Unix Time: 1264145516