[JS] How to get the time and unixtime
Self explanatory code:
var T = {
getUnixTime: function() {
return parseInt(new Date().getTime().toString().substring(0, 10));
},
// format hh:mm:ss
getTime: function()
{
var d= new Date();
var time = new Array();
var hours = d.getHours();
time.push(hours);
var minutes = d.getMinutes().toString().length < 2 ? "0"+d.getMinutes() : d.getMinutes();
time.push(minutes);
var seconds = d.getSeconds().toString().length < 2 ? "0"+d.getSeconds() : d.getSeconds();
time.push(seconds);
return time.join(":");
}
}
Update: I’ve just discovered that Syntax Highlighter code doesn’t work well with < > symbols in javascript code….