Is there a way to chain javascript date functions?
for example, I would like to something like this:
var d = new Date().setMinutes(0).setSeconds(0).setMilliseconds(0);
this syntax breaks with error:
(new Date).setMinutes(0).setSeconds is not a function
I know I can do this:
var d = new Date();
d.setMinutes(0);
d.setSeconds(0);
d.setMilliseconds(0);
but this feels verbose and cumbersome. Is there a better way?
You can set seconds and msecs with the setMinutes method:
var d = new Date();
d.setMinutes(0,0,0);
Also works with hours- d.setHours(0,0,0,0);
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