显示当前日期、时间的JS代码

avatar 2019年11月21日13:02:51 评论 60
<script type="text/javascript">today = new Date();
    var day;
    var date;
    var hello;
    hour = new Date().getHours();
    if (hour < 6) {
        hello = ' 凌晨好! ';
    } else if (hour < 9) {
        hello = ' 早上好!';
    } else if (hour < 12) {
        hello = ' 上午好!';
    } else if (hour < 14) {
        hello = ' 中午好! ';
    } else if (hour < 17) {
        hello = ' 下午好! ';
    } else if (hour < 19) {
        hello = ' 傍晚好!';
    } else if (hour < 22) {
        hello = ' 晚上好! ';
    } else {
        hello = '夜深了! ';
    }
    function GetCookie(sName) {
        var arr = document.cookie.match(new RegExp("(^| )" + sName + "=([^;]*)(;|$)"));
        if (arr != null) {
            return unescape(arr[2])
        };
        return null;
    }
    var Guest_Name = decodeURIComponent(GetCookie('author'));
    var webUrl = webUrl;
    if (Guest_Name != "null") {
        hello = Guest_Name + ' , ' + hello + ' 欢迎回来。';
    }
    document.write(' ' + hello);</script>
<script type="text/javascript">var d, s = "";
    var x = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六");
    d = new Date();
    s += d.getFullYear() + "年" + (d.getMonth() + 1) + "月" + d.getDate() + "日 ";
    s += x[d.getDay()];
    document.writeln(s);</script>
weinxin
我的微信
这是我的微信二维码,申请时请务必写明目的!
avatar

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: