redirectClock.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. var stopTime;
  2. function startTimer() {
  3. var today = new Date();
  4. stopTime = today.getTime() + 120 * 1000;
  5. console.log("Timer start.");
  6. }
  7. function nowTime() {
  8. Date.prototype.Format = function (fmt) {
  9. var o = {
  10. "M+": this.getMonth() + 1, //月份
  11. "d+": this.getDate(), //日
  12. "h+": this.getHours(), //小时
  13. "m+": this.getMinutes(), //分
  14. "s+": this.getSeconds(), //秒
  15. "q+": Math.floor((this.getMonth() + 3) / 3), //季度
  16. S: this.getMilliseconds(), //毫秒
  17. };
  18. if (/(y+)/.test(fmt))
  19. fmt = fmt.replace(
  20. RegExp.$1,
  21. (this.getFullYear() + "").substr(4 - RegExp.$1.length)
  22. );
  23. for (var k in o)
  24. if (new RegExp("(" + k + ")").test(fmt))
  25. fmt = fmt.replace(
  26. RegExp.$1,
  27. RegExp.$1.length == 1
  28. ? o[k]
  29. : ("00" + o[k]).substr(("" + o[k]).length)
  30. );
  31. return fmt;
  32. };
  33. var nowdate = new Date().Format("yyyyMM");
  34. var nowtime = new Date().Format("yyyy-MM-dd hh:mm:ss");
  35. document.getElementById("nowTime").innerHTML = "" + nowtime;
  36. setTimeout(nowTime, 500);
  37. }
  38. function toClipboard() {
  39. var text = document.getElementById("nowTime").innerText;
  40. var input = document.getElementById("textarea");
  41. input.value = text;
  42. input.select();
  43. document.execCommand("copy");
  44. alert("复制成功");
  45. }