首页 > 编程语言 > 详细

javascript获取系统当前时间

时间:2015-07-04 01:05:55      阅读:156      评论:0      收藏:0      [点我收藏+]

function getCurrentDate() {

   var now = new Date();

   var dataStr = now.getFullYear() + "-";

   if (now.getMonth() + 1 < 10) {

      dataStr += "0" + (now.getMonth() + 1);

   } else {

      dataStr += (now.getMonth() + 1);

   }

   dataStr += "-";

   if (now.getDate() < 10) {

      dataStr += "0" + now.getDate();

   } else {

      dataStr += now.getDate();

   }

   dataStr += " ";

   if (now.getHours() < 10) {

      dataStr += "0" + now.getHours();

   } else {

      dataStr += now.getHours();

   }

   dataStr += ":";

   if (now.getMinutes() < 10) {

      dataStr += "0" + now.getMinutes();

   } else {

      dataStr += now.getMinutes();

   }

   dataStr += ":";

   if (now.getSeconds() < 10) {

      dataStr += "0" + now.getSeconds();

   } else {

      dataStr += now.getSeconds();

   }

   $("#showCurrentTime").text(dataStr);

}

window.setInterval("getCurrentDate()", 1000);


javascript获取系统当前时间

原文:http://hundage.blog.51cto.com/3779401/1670637

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!