js calculated difference between the current time and the time of the incoming

No non-nullable processing
function timeQuantum (Time) {
Time = new new a Date (the parseInt (Time)); // Get the time was converted to the incoming date type
var nowTime = new Date (); // get the current time
var timeDifference = time.getTime () - nowTime.getTime () ; // number of milliseconds time difference
IF (the TimeDifference <0) {
return "exceeds a predetermined processing time";
} the else {
var = Days Math.floor (the TimeDifference / (24 * 3600 * 1000)); // calculate the number of days difference
var leave1 = timeDifference% (24 * 3600 * 1000); // number of days after the remaining number of milliseconds
var hours = Math.floor (leave1 / ( 3600 * 1000)); / / calculated hours
var leave2 = leave1% (3600 * 1000); // calculate the number of milliseconds after the remaining number of hours
var minutes = Math.floor (leave2 / ( 60 * 1000)); // calculate the difference between the number of minutes
var leave3 = leave2% (60 * 1000) ; // calculate the number of milliseconds after the number of minutes remaining
var seconds = Math.round (leave3 / 1000 ); // calculate the difference between the number of seconds
return days + "days" + hours + "h" + minutes + "min" + seconds + "seconds";
}
}

Released four original articles · won praise 3 · Views 2477

Guess you like

Origin blog.csdn.net/ZQ960214/article/details/81905364