The way to do it, get midnight of the current day for example:-
var date = new Date(); // Datetime now date.setHours(0, 0, 0, 0); console.log(date); // Midnight today 00:00:00.000
The setHours function returns a timestamp rather than a Date object, but it will modify 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); // Midnight today 00:00:00.000 var hourBeforeMidnight = timestamp - (60 * 60 * 1000); var otherDate = new Date(hourBeforeMidnight); // Date one hour before
The timestamp is the same value you would get if you called getTime.
var timestamp = date.getTime();