Reputation: 162
I have a problem. I have date picker in my web and when I pick date time must be 00. This is what I tried:
qs.date = 2020-11-04T22:00:00.000Z
qs.date = new Date($scope.input.date.getFullYear(),$scope.input.date.getMonth(),$scope.input.date.getDate()+1,0,0,0);
And it does not change the hours to 0 it always stays 22
Also I tried to use this:
qs.date.setHours(0,0,0);
qs.date = qs.date.toISOString();
But no luck.
Upvotes: 0
Views: 2565
Reputation: 11
qs.date = new Date($scope.input.date);
qs.date.setHours(0, 0, 0, 0);
Upvotes: 0
Reputation: 1075655
You're using setHours
, where the time is expressed in the local timezone of the browser, but then you're using toISOString
, which gives you a string expressed in UTC. If you want the time to be 00:00:00
UTC, use setUTCHours
: .setUTCHours(0, 0, 0, 0)
(note that fourth 0
— milliseconds [thanks RobG!]).
Upvotes: 3