Javascript to format date like mm/dd/yyyy hh:mm:ss

[code lang=”js”]

var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1;//January is 0!
var yyyy = today.getFullYear();
var hours = today.getHours();
var minutes = today.getMinutes();
var seconds = today.getSeconds();
if(dd<10){dd=’0’+dd}
if(mm<10){mm=’0’+mm}
d=mm+’/’+dd+’/’+yyyy+’ ‘+hours+’:’+minutes+’:’+seconds

[/code]

This entry was posted in Code and tagged , , , .

Post a Comment

You must be logged in to post a comment.