Monday, November 3, 2008

Javascript: Function To Get Currrent Time

function getCurrentTime()
{
var d = new Date();

var hour=d.getHours();
var minute=d.getMinutes();
var second=d.getSeconds();

if(hour<10)
{
hour = '0'+hour;
}
if(minute<10)
{
minute= '0'+minute;
}

if(second<10)
{
second= '0'+second;
}

var time =hour+':'+minute+':'+second

return time;
}

No comments: