JavaScript Equivalent of PHP Time() in UNIX Format

by keif on April 23, 2009

In PHP you have the time() function to pull the UNIX Timestamp:
[code lang=”php”]
$unix_time = time();
echo $unix_time;
[/code]

We don’t have an easy-as-pie solution for JavaScript however – instead, we have this function we can use:
[code lang=”javascript”]
function unix_time()
{
// tada!
return parseInt(new Date().getTime().toString().substring(0, 10));
}
[/code]

Comments on this entry are closed.

Previous post:

Next post: