var miliseconds = Math.abs(d - new Date());
var today = new Date() // empty constructor returns the "now" time.
Returns the number of miliseconds between the two dates. Using Math.abs
ensures you always get a positive result.
Domanda
How would I go about to get the amount of milliseconds and a specific data. For Instance, i know how to create a date:
var d = new Date(2014,02,22,12,0,0,0);
and to get today's date:
(new Date()).getTime() + 10*24*60*60*1000;
But now how would I go about to get the total milliseconds until this date occurs?
Soluzione
var miliseconds = Math.abs(d - new Date());
var today = new Date() // empty constructor returns the "now" time.
Returns the number of miliseconds between the two dates. Using Math.abs
ensures you always get a positive result.
Altri suggerimenti
Well its a matter of subtracting.
var d = new Date(2014,02,22,12,0,0,0);
var today = new Date();
var ms = d-today;
document.write(ms);
Output:
28015951707