代码示例:(标识:jsck_datetime)
<!DOCTYPE html>
<html>
<body>

<p>单击按钮可显示时间。</p>

<button onclick="myFunction()">试一试</button>

<p id="demo"></p>

<script>
function addZero(i) {
  if (i < 10) {
    i = "0" + i;
  }
  return i;
}

function myFunction() {
  var d = new Date();
  var x = document.getElementById("demo");
  var h = addZero(d.getHours());
  var m = addZero(d.getMinutes());
  var s = addZero(d.getSeconds());
  x.innerHTML = h + ":" + m + ":" + s;
}
</script>

</body>
</html>
运行结果: