帮我写一个html时间代码
时间: 2023-03-26 13:00:57 浏览: 68
好的,以下是一个简单的 HTML 时间代码:
<!DOCTYPE html>
<html>
<head>
<title>时间</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.">
</head>
<body>
<p>现在的时间是:</p>
<p id="time"></p>
<script>
var now = new Date();
var year = now.getFullYear();
var month = now.getMonth() + 1;
var day = now.getDate();
var hour = now.getHours();
var minute = now.getMinutes();
var second = now.getSeconds();
document.getElementById("time").innerHTML = year + "年" + month + "月" + day + "日 " + hour + ":" + minute + ":" + second;
</script>
</body>
</html>
相关问题
帮我写一个html时间代码有年月日秒白色字体
好的,以下是您需要的 HTML 代码:
```html
<p style="color:white;">当前时间为:<span id="time"></span></p>
<script>
function updateTime() {
var now = new Date();
var year = now.getFullYear();
var month = now.getMonth() + 1;
var day = now.getDate();
var hour = now.getHours();
var minute = now.getMinutes();
var second = now.getSeconds();
var timeStr = year + "年" + month + "月" + day + "日 " + hour + ":" + minute + ":" + second;
document.getElementById("time").innerHTML = timeStr;
}
setInterval(updateTime, 100);
</script>
```
这段代码会在页面上显示当前时间,格式为“年月日 时分秒”,字体为白色。
帮我写一个html时间代码有年月日时分秒星期 白色字体
好的,以下是代码:
<!DOCTYPE html>
<html>
<head>
<title>时间</title>
<style>
body {
background-color: black;
color: white;
font-size: 50px;
text-align: center;
margin-top: 200px;
}
</style>
</head>
<body>
<script>
function updateTime() {
var now = new Date();
var year = now.getFullYear();
var month = now.getMonth() + 1;
var day = now.getDate();
var hour = now.getHours();
var minute = now.getMinutes();
var second = now.getSeconds();
var weekDay = now.getDay();
var weekDays = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
var timeString = year + "年" + month + "月" + day + "日 " + hour + ":" + minute + ":" + second + " " + weekDays[weekDay];
document.body.innerHTML = timeString;
}
setInterval(updateTime, 100);
</script>
</body>
</html>
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)