This code results in an output of 1. Why is this when the argument to setTime is the number of milliseconds added to midnight Jan 1 1970? Surely it should be 0?
var d = new Date();
d.setTime(0);
console.log(d.getHours());
you can do this
var d = new Date();
d.setTime(0);
console.log(d.getUTCHours());
thing is getHours give time at your timezone(local timezone), to get the UTC time just change it to getUTCHours
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