Tuesday, November 10, 2009

timestamp from javascript date

Hi everybody, here's simple extension for javascript Date object. It returns timestamp in seconds in local time. Locale is taken from users browser.

Date.prototype.getTimestamp = function () 
{
var date = this;
var timestamp = Math.round(date.getTime()/1000);
timestamp = timestamp - (date.getTimezoneOffset () * 60);

return timestamp;
}


usage is simple:

var new_Date = Date();
alert(date.getTimestamp());

No comments: