Emilis
Emilis

Reputation: 162

How to set Date time to 00 Javascript

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.

network header

Upvotes: 0

Views: 2565

Answers (2)

sajiyya k
sajiyya k

Reputation: 11

qs.date = new Date($scope.input.date);

qs.date.setHours(0, 0, 0, 0);

Upvotes: 0

T.J. Crowder
T.J. Crowder

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

Related Questions