Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to chain javascript date functions

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?

like image 682
MyTimeFinder Avatar asked May 29 '13 00:05

MyTimeFinder


1 Answers

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);

like image 150
kennebec Avatar answered Sep 23 '22 11:09

kennebec