What is the best way to calculate the time passed since (last) midnight in ms?
The getTime() method returns the number of milliseconds since the ECMAScript epoch. You can use this method to help assign a date and time to another Date object. This method is functionally equivalent to the valueOf() method.
In JavaScript, a time stamp is the number of milliseconds that have passed since January 1, 1970.
A Timestamp represents a point in time independent of any time zone or calendar, represented as seconds and fractions of seconds at nanosecond resolution in UTC Epoch time. It is encoded using the Proleptic Gregorian Calendar which extends the Gregorian calendar backwards to year one.
Create a new date using the current day/month/year, and get the difference.
var now = new Date(), then = new Date( now.getFullYear(), now.getMonth(), now.getDate(), 0,0,0), diff = now.getTime() - then.getTime(); // difference in milliseconds
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