I want to convert a date string '03/08/2016' to date object without a timezone.
convertToDateFormat(Datestr) {
if ( Datestr!="" ) { // Datestr="03/08/2016"
var datedata = Datestr.split("/");
let year=datedata[2];
let month=(parseFloat(datedata[1]) - 1);
let day=datedata[0];
var formatedDate = new Date( month + '-' + day + '-' + year);
var formatedDatestring=JSON.stringify(formatedDate);
}
}
Here I got the formatedDate as a Date object as
Wed Aug 03 2016 15:20:58 GMT+0530 (India Standard Time)
and stringify it I got the formatedDatestring as
"2016-08-02T18:30:00.000Z"
But I want the formatedDatestring as "2016-08-03T00:00:00.000Z"
You're overcomplicating
function convertToDateFormat(Datestr) {
if ( Datestr!="" ) { // Datestr="03/08/2016"
var datedata = Datestr.split("/");
var formatedDateString=datedata[2]+'-' + datedata[1] + '-' + datedata[0] + 'T00:00:00.000Z';
return formatedDateString;
}
}
console.log(convertToDateFormat("03/08/2016")) // 2016-08-03T00:00:00.000Z