码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2015-08-20 18:21:15      阅读:114      评论:0      收藏:0      [点我收藏+]

标签:

不多说自己上代码

这是我开始学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显示当前的时间(年月日 时分秒 星期)

标签:

原文地址:http://www.cnblogs.com/kingdudu/p/4745675.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!