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

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

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

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

<script>
function addZero(x,n) {
  while (x.toString().length < n) {
    x = "0" + x;
  }
  return x;
}

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

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