📜  javascript 实时时间 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:01.488000             🧑  作者: Mango

代码示例1
var span = document.getElementById('span');

function time() {
  var d = new Date();
  var s = d.getSeconds();
  var m = d.getMinutes();
  var h = d.getHours();
  span.textContent = 
    ("0" + h)+ ":" + ("0" + m).substr(-2) + ":" + ("0" + s);
}

setInterval(time, 1000);