I need to convert Mon Mar 07 2016 00:00:00 GMT-0500 (Eastern Standard Time)
to `MM/DD/YYYY' format in javascript.
How can I do that?
I need to convert Mon Mar 07 2016 00:00:00 GMT-0500 (Eastern Standard Time)
to `MM/DD/YYYY' format in javascript.
How can I do that?
Would something like this work for you? This is Maerics function literally the first post when I typed "Javascript change date format" the only difference is creating a new date out of the string and passing it into the function.
var tmpDate = new Date("Mon Mar 07 2016 00:00:00 GMT-0500 (Eastern Standard Time)")
function convertDate(inputFormat) {
function pad(s) { return (s < 10) ? '0' + s : s; }
var d = new Date(inputFormat);
return [pad(d.getDate()), pad(d.getMonth()+1), d.getFullYear()].join('/');
}
var shortDate = convertDate(tmpDate);
console.log(shortDate);
what about getting a date like this:
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!
var yyyy = today.getFullYear();
if(dd<10) {
dd='0'+dd
}
if(mm<10) {
mm='0'+mm
}
today = mm+'/'+dd+'/'+yyyy;
document.write(today);