【第六篇】javascript显示当前的时间(年月日 时分秒 星期)

不多说自己上代码

这是我开始学javascript写的,现在发出来

<span  id="clock" ></span>
function time() {
var today = new Date();
var hou;
var time;
var day;
if (today.getHours() < 12 && today.getHours() >= 0) {
hou = today.getHours();
time = "AM";
} else if (today.getHours() <= 24 && today.getHours() > 12) {
hou = today.getHours() - 12;
time = "PM";
}
var d = today.getDay();
if (d == 0) {
day = "日";
} else if (d == 1) {
day = "一";
} else if (d == 2) {
day = "二";
} else if (d == 3) {
day = "三";
} else if (d == 4) {
day = "四";
} else if (d == 5) {
day = "五";
} else if (d == 6) {
day = "六";
}
document.getElementById("clock").innerHTML = (today.getFullYear() + "年" + (today.getMonth() + 1) + "月" + today.getDate() + "日&nbsp;" + hou + ":" + today.getMinutes() + ":" + today.getSeconds() + "&nbsp;" + time + "&nbsp;星期" + day);
}
var myTime = setInterval("time()", 1000);

效果图

【第六篇】javascript显示当前的时间(年月日 时分秒 星期)

---------------------------------------------------------------------------------------------------------

转载请记得说明作者和出处哦-.-
作者:KingDuDu
原文出处:https://www.cnblogs.com/kingdudu/articles/4745675.html

---------------------------------------------------------------------------------------------------------

上一篇:jquery基础学习之DOM篇(二)


下一篇:YIi 权限管理和基于角色的访问控制