<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>時間</title>
</head>
<body>
<span id="mytime"></span>
<script>
function showTime(){
nowtime = new Date();//
year = nowtime.getFullYear();//獲取當前完整的年份
month = nowtime.getMonth()+1;//獲取當前月份
date = nowtime.getDate();//獲取當前日
document.getElementById("mytime").innerText = year+"年"+month+"月"+date+"日"+nowtime.toLocaleTimeString();//toLocaleTimeString()根據本地時間把 Date 物件的時間部分轉換為字串
}
function showTime2(){
document.getElementById("mytime").innerText = new Date();
}
setInterval('showTime()',1000);//1秒更新一次
</script>
</body>
</html>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/244299.html
標籤:其他
