Clive Walkden

PHP, MySQL, HTML5, CSS3, jQuery code and ideas.

jQuery Posts

PHP Time() Equivalent for Javascript

PHP Time() Equivalent for Javascript

in jQuery
with 0 Comments

This function utilises the Date object. When the Date.getTime() object instance is created it calls the number of seconds since 1 January 1970 UTC. As we only want the number of seconds (not milliseconds) we divide the result by 1000.

The Math.floor part rounds the number down to the nearest whole number.

function time() {
    var timestamp = Math.floor(new Date().getTime() / 1000)
    return timestamp;

comments powered by Disqus