First you must define an array of English words (Sunday, Monday, February, March, etc.):
var daysOfWeek = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"], monthsOfYear = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
To insert an extra 0 at the beginning of minutes and seconds, define a fill function for the String prototype:
String.prototype.padLeft = function(padString,length){ var toReturn = String(this); while(toReturn.length < length){ toReturn = padString + toReturn; } return toReturn; }
Format the date and time as follows:
var time = new Date(), formattedDate, formattedTime, wholeThing; formattedDate = daysOfWeek[time.getDay()] + ", " + monthsOfYear[time.getMonth()] + " " + time.getDate() + ", " + time.getFullYear(); formattedTime = time.getHours() + ":" + time.getMinutes().padLeft("0",2) + time.getSeconds().padLeft("0",2);
You can get all this by combining formattedDate and formattedTime , as in:
wholeThing = formattedDate + " " + formattedTime;