简单教程
提交运行
代码编辑器:
<p id="demo">单击按钮显示UTC时间</p> <button onclick="myFunction()">点我</button> <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.getUTCHours()); var m=addZero(d.getUTCMinutes()); var s=addZero(d.getUTCSeconds()); x.innerHTML=h + ":" + m + ":" + s; } </script>
运行结果: