What is the simplest way to obtain an instance of new Date() but set the time at midnight?
+1
A:
Give Date() only parameters for Year, month and day. The Time will be set to O:00:00 in this case.
new Date(2010, 9 , 8);
...will set the Date to october 8th 2010 0:00
I would'nt say it's the best, but as long as it will do the same like the other proposals, for me it's the best, because the shortest ^^
Dr.Molle
2010-10-08 20:28:31
+4
A:
The setHours method can take optional minutes, seconds and ms arguments, for example:
var d = new Date();
d.setHours(0,0,0,0);
That will set the time to 00:00:00.000 of your current timezone, if you want to work in UTC time, you can use the setUTCHours method.
CMS
2010-10-08 20:31:43
Brilliant! Exactly what I was looking for.
Sixty4Bit
2010-10-08 20:33:50