日期時間在線顯示 日期時間在線顯示可全屏
Megamarket大市場購賣家服務2025-06-267860
要在線顯示日期和時間,可以使用HTML、CSS和JavaScript。以下是一個簡單的示例:
- 創(chuàng)建一個HTML文件,例如
index.html
,并添加以下內(nèi)容:
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>日期時間顯示</title>
<style>
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="date-time"></div>
<script src="script.js"></script>
</body>
</html>
- 接下來,創(chuàng)建一個名為
script.js
的JavaScript文件,并添加以下內(nèi)容:
// 獲取日期和時間元素
const dateTimeElement = document.getElementById('date-time');
// 設置日期和時間為當前時間
function setDateTime() {
const now = new Date();
dateTimeElement.textContent = `${now.toLocaleString()}`;
}
// 每秒更新一次日期和時間
setInterval(setDateTime, 1000);
- 在瀏覽器中打開
index.html
文件,你將看到一個簡單的頁面,顯示當前的日期和時間。
本文內(nèi)容根據(jù)網(wǎng)絡資料整理,出于傳遞更多信息之目的,不代表金鑰匙跨境贊同其觀點和立場。
轉載請注明,如有侵權,聯(lián)系刪除。