I want to set time to 0 using javascript's setHours() method but it changes the day of the month to one less than the actual day. Sample code:
var d = new Date();  //2017-09-18T04:58:34.223Z
d.setHours(0,0,0,0);  //2017-09-17T18:30:00.000Z
                The setHours() method sets the hours for a specified date according to local time, and returns the number of milliseconds since 1 January 1970 00:00:00 UTC until the time represented by the updated Date instance.
To set the time to midnight in universal time ,use setUTCHours().
The getUTCHours() method returns the hours in the specified date according to universal time.
var date = new Date();
console.log(date.toISOString());
date.setUTCHours(0,0,0,0);
console.log(date.toISOString());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With