首页 > 代码库 > getContinueTime() JavaScript计算一个事件已进行的时间

getContinueTime() JavaScript计算一个事件已进行的时间

function getContinueTime(startTime) {    //当前时间与指定的时间的差值    var time = (new Date() - new Date(startTime)) / 1000,        serviceTime = ‘‘,        days = Math.floor(time / 3600 / 24),        hours = Math.floor(time / 3600 % 24),        minutes = Math.floor(time / 60 % 60),        seconds = Math.floor(time % 60);    hours = hours && hours < 10 ? ‘0‘ + hours : hours;    minutes = minutes && minutes < 10 ? ‘0‘ + minutes : minutes;    seconds = seconds && seconds < 10 ? ‘0‘ + seconds : seconds;    days ? serviceTime += days + ‘天‘ : ‘‘;    hours ? serviceTime += hours + ‘时‘ : ‘‘;    minutes ? serviceTime += minutes + ‘分‘ : ‘‘;    serviceTime += seconds + ‘秒‘;    return serviceTime}getContinueTime(‘2015/01/01‘);

 

getContinueTime() JavaScript计算一个事件已进行的时间