Clock.js
资源名称:a.rar [点击查看]
上传用户:aa118c
上传日期:2021-05-13
资源大小:4785k
文件大小:1k
源码类别:

WEB源码(ASP,PHP,...)

开发平台:

HTML/CSS

  1. function Clock() {
  2. var date = new Date();
  3. this.year = date.getFullYear();
  4. this.month = date.getMonth() + 1;
  5. this.date = date.getDate();
  6. this.day = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六")[date.getDay()];
  7. this.hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
  8. this.minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
  9. this.second = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
  10. this.toString = function() {
  11. return "现在是:" + this.year + "年" + this.month + "月" + this.date + "日 " + this.hour + ":" + this.minute + ":" + this.second + " " + this.day; 
  12. };
  13. this.toSimpleDate = function() {
  14. return this.year + "-" + this.month + "-" + this.date;
  15. };
  16. this.toDetailDate = function() {
  17. return this.year + "-" + this.month + "-" + this.date + " " + this.hour + ":" + this.minute + ":" + this.second;
  18. };
  19. this.display = function(ele) {
  20. var clock = new Clock();
  21. ele.innerHTML = clock.toString();
  22. window.setTimeout(function() {clock.display(ele);}, 1000);
  23. };
  24. }