实现计时、时钟,实时获取当前年月日时分秒,记录时间(获取当前的时间,开始计时,计时过程相当于你的电脑时钟)0000年00月00日 00:00:00
生活随笔
收集整理的這篇文章主要介紹了
实现计时、时钟,实时获取当前年月日时分秒,记录时间(获取当前的时间,开始计时,计时过程相当于你的电脑时钟)0000年00月00日 00:00:00
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
?
?
?
<!doctype html>
<html lang="en">
<head><meta charset="UTF-8"><title>現在時刻</title>
</head>
<body>
<div id="now"></div>
</body>
<script>/*實現計時,記錄時間(獲取當前的時間,開始計時,計時過程相當于你的電腦時鐘)0000年00月00日 00:00:00*/function now(id) {let div = document.getElementById(id);let date = new Date();let year = date.getFullYear();let month = date.getMonth() + 1;let day = date.getDate();let hours = date.getHours();let minutes = date.getMinutes();let seconds = date.getSeconds();month = month < 10 ? "0" + month : month;day = day < 10 ? "0" + day : day;hours = hours < 10 ? "0" + hours : hours;minutes = minutes < 10 ? "0" + minutes : minutes;seconds = seconds < 10 ? "0" + seconds : seconds;div.innerHTML = "現在時間:" + year + "年" + month + "月" + day + "日" + " " + hours + ":" + minutes + ":" + seconds;/* div.innerHTML = "現在時間:" + year + "年" + month + "月" + day + "日" + " " + hours + "時" + minutes + "分" + seconds + "秒";*/}now("now"), setInterval("now('now')", 1000);
</script>
</html>
總結
以上是生活随笔為你收集整理的实现计时、时钟,实时获取当前年月日时分秒,记录时间(获取当前的时间,开始计时,计时过程相当于你的电脑时钟)0000年00月00日 00:00:00的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【longPressKey】长按键盘任意
- 下一篇: vue3.0环境搭建