<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content=
"width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document
title>
head>
<body>
<div class="week">
div>
<div class="date">
div>
<div class="time">
div>
<div class="duan">
div>
body>
<script>
function Mtime(ele,duan){
setInterval(
function(){
var date =
new
Date();
var seperator1 =
"-";
var seperator2 =
":";
var month = date.getMonth() +
1;
var strDate = date.getDate();
var hour = date.getHours();
var minutes = date.getMinutes();
var seconds = date.getSeconds();
if (month >=
1 && month <=
9) {
month =
"0" + month;
}
if (strDate >=
0 && strDate <=
9) {
strDate =
"0" + strDate;
}
if (minutes >=
0 && minutes <=
9) {
minutes =
"0" + minutes;
}
if (seconds >=
0 && seconds <=
9) {
seconds =
"0" + seconds;
}
if(hour <
6){
document.write(
"凌晨好!")}
else
if (hour <
9){duan.innerHTML=
"早上好"}
else
if (hour <
12){duan.innerHTML=
"上午好"}
else
if (hour <
14){duan.innerHTML=
"中午好"}
else
if (hour <
17){duan.innerHTML=
"下午好"}
else
if (hour <
19){duan.innerHTML=
"傍晚好"}
else
if (hour <
22){duan.innerHTML=
"晚上好"}
else {
document.write(
"夜里好!")}
var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
+
" " + date.getHours() + seperator2 + minutes
+ seperator2 + seconds;
ele.innerHTML=currentdate;
},
1000);
}
function week(ele) {
var str =
'星期';
var week =
new
Date().getDay();
switch (week) {
case
0 :
str +=
"日";
break;
case
1 :
str +=
"一";
break;
case
2 :
str +=
"二";
break;
case
3 :
str +=
"三";
break;
case
4 :
str +=
"四";
break;
case
5 :
str +=
"五";
break;
case
6 :
str +=
"六";
break;
}
ele.innerHTML=str;
}
Mtime(
document.getElementsByClassName(
"time")[
0],
document.getElementsByClassName(
"duan")[
0]);
week(
document.getElementsByClassName(
"week")[
0]);
script>
html>