Trying to display just the date by doing this:
let myDate="2015-03-08T04:49:49.431Z";
console.log(new Date(myDate).toUTCString('dd-mm-yyyy'));
Still returns the time , how can I just return the date?
Trying to display just the date by doing this:
let myDate="2015-03-08T04:49:49.431Z";
console.log(new Date(myDate).toUTCString('dd-mm-yyyy'));
Still returns the time , how can I just return the date?
var myDate="2015-03-08T04:49:49.431Z";
new Date(myDate).toLocaleDateString(); // "3/8/2015"
new Date(myDate).toDateString(); // "Sun Mar 08 2015"
You can check all other methods here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date
You could do something like:
let myDate = "2015-03-08T04:49:49.431Z";
let date = new Date(myDate);
let dateString = ("0" + date.getUTCDate()).slice(-2) + "-" + ("0" + (date.getUTCMonth()+1)).slice(-2) + "-" + date.getUTCFullYear();
console.log(dateString);
.toUTCString()
does not accept any arguments.