/**
* ??????????????,????????
* English: Calculating the difference between the given time and the current time and then showing the results.
*/
function date2Text(date) {
var milliseconds = new Date() - date;
var timespan = new TimeSpan(milliseconds);
if (milliseconds < 0) {
return timespan.toString() + "??";
}else{
return timespan.toString() + "?";
}
}
/**
* ???????????
* English: Using a function to calculate the time interval
* @param milliseconds ???
*/
var TimeSpan = function (milliseconds) {
milliseconds = Math.abs(milliseconds);
var days = Math.floor(milliseconds / (1000 * 60 * 60 * 24));
milliseconds -= days * (1000 * 60 * 60 * 24);
var hours = Math.floor(milliseconds / (1000 * 60 * 60));
milliseconds -= hours * (1000 * 60 * 60);
var mins = Math.floor(milliseconds / (1000 * 60));
milliseconds -= mins * (1000 * 60);
var seconds = Math.floor(milliseconds / (1000));
milliseconds -= seconds * (1000);
return {
getDays: function () {
return days;
},
getHours: function () {
return hours;
},
getMinuts: function () {
return mins;
},
getSeconds: function () {
return seconds;
},
toString: function () {
var str = "";
if (days > 0 || str.length > 0) {
str += days + "?";
}
if (hours > 0 || str.length > 0) {
str += hours + "??";
}
if (mins > 0 || str.length > 0) {
str += mins + "??";
}
if (days == 0 && (seconds > 0 || str.length > 0)) {
str += seconds + "?";
}
return str;
}
}
}