SHARE
TWEET

Untitled

a guest Jul 24th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * 倒计时
  3.  * @param now 现在的时间
  4.  * @param startTime 计时开始时间
  5.  * @param endTime 计时结束时间
  6.  * @returns {*} 计时标识
  7.  */
  8. function countDown(startTime, endTime) {
  9.     var now = Date.now();
  10.     if (now < startTime) {
  11.         return "距离开始还剩" + calTime(startTime - now);
  12.     }
  13.     if (now < endTime) {
  14.  
  15.         return "距离结束还剩" + calTime(endTime - now);
  16.     }
  17.     return "已经结束" + calTime(now - endTime);
  18. }
  19.  
  20. /**
  21.  * 计算与目标时间相差几天、几时、几分、几秒
  22.  * @param diff
  23.  * @returns {string}
  24.  */
  25. function calTime(diff) {
  26.     var days = parseInt(diff / 1000 / 60 / 60 / 24);
  27.     var hours = parseInt(diff / 1000 / 60 / 60) % 24;
  28.     var mins = parseInt(diff / 1000 / 60) % 60;
  29.     var seconds = parseInt(diff / 1000) % 60;
  30.     return transFormat(days) + '天 ' + transFormat(hours) + ':' + transFormat(mins) + ':' + transFormat(seconds);
  31. }
  32.  
  33. document.write(countDown(1509019200000,1509026400000));
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top