I have this information: 2014-12-29T22:04:56.000Z
I would like to get the 2014-12-29 part of it in 12/29/2014 format.
How can I do it in javascript?
Thanks!
I have this information: 2014-12-29T22:04:56.000Z
I would like to get the 2014-12-29 part of it in 12/29/2014 format.
How can I do it in javascript?
Thanks!
You could format the date like this to get your desired formatting.
var date = new Date("2014-12-29T22:04:56.000Z");
function pad(number) {
if (number < 10) {
return '0' + number;
}
return number;
}
function formatDate() {
return pad(date.getUTCMonth() + 1) +
'/' + pad(date.getUTCDate()) + '/' + date.getUTCFullYear();
}
console.log(formatDate())
You could do this using RegExp replace:
var ds = '2014-12-29T22:04:56.000Z';
console.log(ds.replace(/^(\d{4})-(\d\d)-(\d\d).+$/, '$2/$3/$1'));
Another approach would be using simple String.slice to get the required parts from the date string:
console.log(ds.slice(5, 7) + '/' + ds.slice(8, 10) + '/' + ds.slice(0, 4));
strMDY = strISO.substring(5, 7) + "/" + strISO.substring(8, 10) + "/" + strISO.substring(0, 4)