以下为网络收集到的 HTML 加载系统当前实时时间的HTML代码,都试试看看效果咯,笔者只是加入了一些小改动。应用时根据自己的实际情况进行更改...
静态时间:
<!DOCTYPE html>
<html>
<head>
<meta content="Author" name="notfound945">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>Now Time</title>
<script type="text/javascript">
var myDate = new Date();
document.write(myDate.toLocaleString())
</script>
</head>
<body>
</body>
</html>
动态实时时间:
<!DOCTYPE html>
<html>
<head>
<meta content="Author" name="notfound945">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>Now Time</title>
<style>
#frame {
height: 120px;
width: 365px;
margin: 200px auto -10px;
border-radius: 25px 0 25px 0;
background-color: #e17724
}
#nowdate {
height: 100%;
width: 380px;
margin: -80px auto;
font-size: 35px;
color: white;
text-align: center;
box-shadow: 5px 5px #e17700;
background-color: #d2e100;
}
</style>
<script>
function mytime(){
var a = new Date();
var b = a.toLocaleTimeString();
var c = a.toLocaleDateString();
document.getElementById("nowdate").innerHTML = c+" "+b;
}
setInterval(function() {mytime()},10);
</script>
</head>
<body>
<div id="frame"></div>
<div id="nowdate"></div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta content="Author" name="notfound945">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>Now Time</title>
<style>
#frame {
height: 120px;
width: 365px;
margin: 200px auto -10px;
border-radius: 25px 0 25px 0;
background-color: #e17724
}
#nowdate {
height: 100%;
width: 380px;
margin: -105px auto;
font-size: 35px;
color: white;
text-align: center;
box-shadow: 5px 5px #e17700;
background-color: #d2e100;
}
</style>
<script>
setInterval("nowdate.innerHTML=new Date().toLocaleString()+' 星期'+'日一二三四五六'.charAt(new Date().getDay());",1000);
</script>
</head>
<body>
<div id="frame"></div>
<div id="nowdate"></div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta content="Author" name="notfound945">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>Now Time</title>
<style>
#frame {
height: 120px;
width: 365px;
margin: 200px auto -10px;
border-radius: 25px 0 25px 0;
background-color: #e17724
}
#Nowtime {
height: 100%;
width: 380px;
margin: -105px auto;
font-size: 35px;
color: white;
text-align: center;
box-shadow: 5px 5px #e17700;
background-color: #d2e100;
}
</style>
<script type="text/javascript">
function show() {
var date = new Date(); //日期对象
var now = "此刻是";
now = now + date.getFullYear() + "年";
now = now + (date.getMonth() + 1) + "月"; //取月的时候取的是当前月-1如果想取当前月+1就可以了
now = now + date.getDate() + "日 ";
now = now + date.getHours() + "时";
now = now + date.getMinutes() + "分";
now = now + date.getSeconds() + "秒";
document.getElementById("Nowtime").innerHTML = now; //div的html是now这个字符串
setTimeout("show()", 1000); //设置过1000毫秒就是1秒,调用show方法
}
</script>
</head>
<body onload="show()"> <!-- 网页加载时只需调用一次 以后就自动调用了-->
<div id="frame"></div>
<div id="Nowtime"></div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta content="Author" name="notfound945">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>Now Time</title>
<style>
#frame {
height: 120px;
width: 365px;
margin: 200px auto -10px;
border-radius: 25px 0 25px 0;
background-color: #e17724
}
#nowdate {
height: 100%;
width: 380px;
margin: -105px auto;
font-size: 35px;
color: white;
text-align: center;
box-shadow: 5px 5px #e17700;
background-color: #d2e100;
}
</style>
<script type="text/javascript">
function getTime() {
var dateObj = new Date();
var year = dateObj.getFullYear();//年
var month = dateObj.getMonth()+1;//月 (注意:月份+1)
var date = dateObj.getDate();//日
var day = dateObj.getDay();
var weeks = ["星期日","星期一","星期二","星期三","星期四","星期五","星期六"];
var week = weeks[day];//根据day值,获取星期数组中的星期数。
var hours = dateObj.getHours();//小时
var minutes = dateObj.getMinutes();//分钟
var seconds = dateObj.getSeconds();//秒
if(month<10){
month = "0"+month;
}
if(date<10){
date = "0"+date;
}
if(hours<10){
hours = "0"+hours;
}
if(minutes<10){
minutes = "0"+minutes;
}
if(seconds<10){
seconds = "0"+seconds;
}
var newDate = year+"年"+month+"月"+date+"日"+hours+":"+minutes+":"+seconds+"   "+week;
document.getElementById("nowdate").innerHTML = "此刻是" + newDate;//在div中写入时间
setTimeout('getTime()', 500);//每隔500ms执行一次getTime()
}
</script>
</head>
<body onload="getTime()">
<div id="frame"></div>
<div id="nowdate"></div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta content="Author" name="notfound945">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>Now Time</title>
<style>
#frame {
height: 120px;
width: 365px;
margin: 200px auto -10px;
border-radius: 25px 0 25px 0;
background-color: #e17724
}
#nowdate {
height: 100%;
width: 380px;
margin: -105px auto;
font-size: 35px;
color: white;
text-align: center;
box-shadow: 5px 5px #e17700;
background-color: #d2e100;
}
</style>
<script>
function fun() {
var date = new Date(); //创建对象
var y = date.getFullYear(); //获取年份
var m = date.getMonth() + 1; //获取月份 返回0-11
var d = date.getDate(); // 获取日
var w = date.getDay(); //获取星期几 返回0-6 (0=星期天)
var ww = ' 星期' + '日一二三四五六'.charAt(new Date().getDay());//星期几
var h = date.getHours(); //时
var minute = date.getMinutes() //分
var s = date.getSeconds(); //秒
var sss = date.getMilliseconds(); //毫秒
if (m < 10) {
m = "0" + m;
}
if (d < 10) {
d = "0" + d;
}
if (h < 10) {
h = "0" + h;
}
if (minute < 10) {
minute = "0" + minute;
}
if (s < 10) {
s = "0" + s;
}
if (sss < 10) {
sss = "00" + sss;
}
else if (sss < 100) {
sss = "0" + sss;
}
document.getElementById("nowdate").innerHTML = y + "-" + m + "-" + d + " " + h + ":" + minute + ":" + s + "." + sss + " " + ww;
setTimeout("fun()",1);//1 ms更新一次
}
</script>
</head>
<body onload="fun()">
<div id="frame"></div>
<div id="nowdate"></div>
</body>
</html>