<!DOCTYPE html>
<html lang="zh-CN">
<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;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #f0f0f0;
}
.container {
text-align: center;
background-color: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
h1 {
color: #333;
margin-bottom: 10px;
}
p {
font-size: 1.2em;
color: #666;
}
button {
background-color: #007BFF;
color: white;
padding: 10px 20px;
font-size: 1em;
border: none;
border-radius: 4px;
cursor: pointer;
transition: background-color 0.3s;
}
button:hover {
background-color: #0056b3;
}
</style>
</head>
<body>
<div class="container">
<h1>实时时间</h1>
<p id="timeInfo"></p>
<button onclick="loadTime()">刷新时间</button>
</div>
<script>
function loadTime() {
fetch('http://api.holytreasure.top/time.php') // 替换为你的服务器地址
.then(response => response.json())
.then(data => {
const timeInfoElement = document.getElementById('timeInfo');
timeInfoElement.innerHTML = `
时间戳: ${data.timestamp}<br>
年: ${data.datetime.year}<br>
月: ${data.datetime.month}<br>
日: ${data.datetime.day}<br>
时: ${data.datetime.hour}<br>
分: ${data.datetime.minute}<br>
秒: ${data.datetime.second}<br>
`;
})
.catch(error => {
console.error('Error:', error);
alert('加载时间失败,请稍后再试。');
});
}
// 页面加载时立即加载一次时间
window.onload = loadTime;
</script>
</body>
</html>