zoukankan      html  css  js  c++  java
  • javascript对时间的处理

       function getMainHead() {

                $("LabelWelcome").innerHTML = GetWelcomeByTime() + "        今天是:" + GetSimpleDate() + "  " + GetWeekDay() + "     " + GetCnDate() + SolarTerm(new Date());

            }

    function GetWelcomeByTime() {

        var now = new Date();

        var hour = now.getHours();

        var hello = "";

     

        if (hour < 4) {

            hello = "夜深了";

        }

        else if (hour < 7) {

            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 = "夜深了";

        }

     

        return hello;

    }

    function GetSimpleDate() {

        var today = new Date();

        var date = (today.getYear() < 100 ? today.getYear() + 1900 : today.getYear()) + "年" + (today.getMonth() + 1) + "月" + today.getDate() + "日";

        return date;

    }

    function GetWeekDay() {

        var today = new Date();

        var weeks = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六");

        return weeks[today.getDay()];

    }

    //获取农历日期

    function GetCnDate() {

        var today = new Date();

        return CnDateofDateStr(today);

    }

    function CnDateofDateStr(DateGL) {

        if (CnMonthofDate(DateGL) == "零月") return " 请调整您的计算机日期!";

        else return "农历:" + CnYearofDate(DateGL) + " " + CnMonthofDate(DateGL) + CnDayofDate(DateGL);

    }

    function SolarTerm(DateGL) {

        var SolarTermStr = new Array(

            "小寒", "大寒", "立春", "雨水", "惊蛰", "春分",

            "清明", "谷雨", "立夏", "小满", "芒种", "夏至",

            "小暑", "大暑", "立秋", "处暑", "白露", "秋分",

            "寒露", "霜降", "立冬", "小雪", "大雪", "冬至");

        var DifferenceInMonth = new Array(

            1272060, 1275495, 1281180, 1289445, 1299225, 1310355,

            1321560, 1333035, 1342770, 1350855, 1356420, 1359045,

            1358580, 1355055, 1348695, 1340040, 1329630, 1318455,

            1306935, 1297380, 1286865, 1277730, 1274550, 1271556);

        var DifferenceInYear = 31556926;

        var BeginTime = new Date(1901 / 1 / 1);

        BeginTime.setTime(947120460000);

        for (; DateGL.getYear() < BeginTime.getYear(); ) {

            BeginTime.setTime(BeginTime.getTime() - DifferenceInYear * 1000);

        }

        for (; DateGL.getYear() > BeginTime.getYear(); ) {

            BeginTime.setTime(BeginTime.getTime() + DifferenceInYear * 1000);

        }

        for (var M = 0; DateGL.getMonth() > BeginTime.getMonth(); M++) {

            BeginTime.setTime(BeginTime.getTime() + DifferenceInMonth[M] * 1000);

        }

        if (DateGL.getDate() > BeginTime.getDate()) {

            BeginTime.setTime(BeginTime.getTime() + DifferenceInMonth[M] * 1000);

            M++;

        }

        if (DateGL.getDate() > BeginTime.getDate()) {

            BeginTime.setTime(BeginTime.getTime() + DifferenceInMonth[M] * 1000);

            M == 23 ? M = 0 : M++;

        }

        var JQ;

        if (DateGL.getDate() == BeginTime.getDate()) {

            JQ = "  今天是<font color='#FF9999'><b>" + SolarTermStr[M] + "</b></font>";

        } 

        else {

            JQ = " " 

        }

        return JQ;

    }

  • 相关阅读:
    bzoj4563: [Haoi2016]放棋子(错排+高精)
    bzoj1089 [SCOI2003]严格n元树(dp+高精)
    9.15NOIP模拟题
    洛谷 P2010 回文日期 题解
    洛谷 P1147 连续自然数和 题解
    洛谷 P1152 欢乐的跳 题解
    信息学奥赛一本通 高手训练1 统计方案数
    想学习找不到好的博客?看这里>>
    信息学奥赛一本通 高手训练1 游戏通关
    洛谷 P3398 仓鼠找sugar 题解
  • 原文地址:https://www.cnblogs.com/fanxiaojun/p/2094932.html
Copyright © 2011-2022 走看看