A way to do this, for example, get the midnight of the current day: -
var date = new Date();
The setHours function returns a timestamp, not a Date object, but it will change the original Date object.
The timestamp can be used to initialize new date objects and perform arithmetic.
var timestamp = new Date().setHours(0, 0, 0, 0); var date = new Date(timestamp);
The timestamp is the same value that you would get if you called getTime .
var timestamp = date.getTime();
source share