Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. <!-- 将文件放置在 _widget 目录下,然后在需要插入的地方调用该 ejs,并使用 id="htmer_time" 调用 -->
  2. <script>
  3. function secondToDate(second) {
  4. if (!second) {
  5. return 0;
  6. }
  7. var time = new Array(0, 0, 0, 0, 0);
  8. if (second >= 365 * 24 * 3600) {
  9. time[0] = parseInt(second / (365 * 24 * 3600));
  10. second %= 365 * 24 * 3600;
  11. }
  12. if (second >= 24 * 3600) {
  13. time[1] = parseInt(second / (24 * 3600));
  14. second %= 24 * 3600;
  15. }
  16. if (second >= 3600) {
  17. time[2] = parseInt(second / 3600);
  18. second %= 3600;
  19. }
  20. if (second >= 60) {
  21. time[3] = parseInt(second / 60);
  22. second %= 60;
  23. }
  24. if (second > 0) {
  25. time[4] = second;
  26. }
  27. return time;
  28. }</script>
  29. <script type="text/javascript" language="javascript">
  30. function setTime() {
  31. var create_time = Math.round(new Date(Date.UTC(2016, 08, 15, 20, 14, 19)).getTime() / 1000);
  32. //由于月份的变量定义在 0-11,所以此处填入的月份需要减 1
  33. var timestamp = Math.round((new Date().getTime() + 8 * 60 * 60 * 1000) / 1000);
  34. currentTime = secondToDate((timestamp - create_time));
  35. currentTimeHtml = currentTime[1] + ' 天 '
  36. + currentTime[2] + ' 时 ' + currentTime[3] + ' 分 ' + currentTime[4]
  37. + ' 秒';
  38. document.getElementById("htmer_time").innerHTML = currentTimeHtml;
  39. } setInterval(setTime, 1000);
  40. </script>
  41. <!-- End Uptime JS -->
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement