怎么实现DIV里面显示出来的时间换行,显示成如下格式: XXXX年XX月XX日 星期X XX时:XX分:XX秒这是我写的代码:<!DOCTYPE html>
<head>
<html>
<meta charset="utf-8">
<title>电子时钟</title>
<style type="text/css">
body{
background-image:电子时钟APP-1.jpg;
width: 1920px;
height:1080px;
}
#time{
width:50%;
}
</style>
<script type="text/javascript">
function getDateDemo(){
var myDate=new Date();
var year=myDate.getFullYear();
var month=myDate.getMonth() + 1;
var date=myDate.getDate();
var day=myDate.getDay();
var hours=myDate.getHours();
var minutes=myDate.getMinutes();
var seconds=myDate.getSeconds();
//月份的显示为两位数字如09月
if(month < 10 ){
month = "0" + month;
}
if(date < 10 ){
date = "0" + date;
}
var dateTime=year+"年"+month+"月"+date+"日"+"星期"+day+"\n"+hours+":"+minutes+":"+seconds;
var divNode = document.getElementById("time");
divNode.innerHTML = dateTime;
}
window.setInterval("getDateDemo()",1000);
</script>
</head>
<body>
<div id="time"></div>
<input type="button" value="一键获取时间" onclick="getDateDemo()">
</body>
</html>
- 2 回答
- 0 关注
- 1573 浏览
相关问题推荐
添加回答
举报
0/150
提交
取消