Reputation: 501
trying to create new date and set it to UTC ISO midnight and get output as following "2017-07-12T00:00:00" but no luck so far.
var dateNow = new Date();
var dateToUTC = dateNow.setUTCHours(0,0,0,0);
/*this gives me an error msg*/
var dateToISO = dateToUTC.toISOString();
Upvotes: 7
Views: 3602
Reputation:
Date.setUTCHours
doesn't return a date, it returns a number (see the docs, here) and mutates the date.
You want this:
var dateNow = new Date();
dateNow.setUTCHours(0,0,0,0);
var dateToISO = dateNow.toISOString();
Upvotes: 13