• JS判断,今天所在季度,第几周, 季度的第几周,年度第几周


    <html>
    <head>
    <title>日期判断 周 月 季 年</title>
    <script type="text/javascript">
    var getMonthWeek = function (a, b, c) {
    var date = new Date(a, parseInt(b) - 1, c), w = date.getDay(), d = date.getDate();
    return Math.ceil( (d + 6 - w) / 7 );
    };

    var getYearWeek = function (a, b, c) {
    var date1 = new Date(a, parseInt(b) - 1, c), date2 = new Date(a, 0, 1),
    d = Math.round((date1.valueOf() - date2.valueOf()) / 86400000);
    return Math.ceil( (d + ((date2.getDay() + 1) - 1)) / 7 );
    };

    var today = new Date();//获取当前时间
    var y = today.getFullYear();
    var m = today.getMonth()+1;
    var d = today.getDate();
    document.write("今天是:",y,"-", m, "-", d, "<br/>");
    document.write( "今天是",y,"年的第 ", getYearWeek(y, m, d), " 周<br/>" );
    document.write( "今天是",m,"月的第 ", getMonthWeek(y, m, d), " 周<br/>" );
    var quarter = "";
    var result = getYearWeek(y, m, d);
    if (m <4) {
    quarter = 1;
    week = result;
    } else if (m < 7) {
    quarter = 2;
    week = result - getYearWeek(y, 4, 1);
    var day = new Date(y, 4, 1);
    if (day.getDay() > 1) {
    week += 1;
    }
    } else if (m < 10) {
    quarter = 3;
    week = result - getYearWeek(y, 7, 1);
    var day = new Date(y, 7, 1);
    if (day.getDay() > 1) {
    week += 1;
    }
    } else {
    quarter = 4;
    week = result - getYearWeek(y, 10, 1);
    var day = new Date(y, 10, 1);
    if (day.getDay() > 1) {
    week += 1;
    }
    }
    document.write( "今天是第",quarter,"季度的第 ", week, " 周" );
    </script>
    </head>
    <body>
    </body>
    </html>

  • 相关阅读:
    Eclipse 开发过程中利用 JavaRebel 提高效率
    数字转化为大写中文
    网页变灰
    解决QQ截图无法在PS中粘贴
    ORACLE操作表时”资源正忙,需指定nowait"的解锁方法
    网页常用代码
    SQL Server 2000 删除注册的服务器
    GridView 显示序号
    读取Excel数据到DataTable
    清除SVN版本控制
  • 原文地址:https://www.cnblogs.com/zhoumeng780/p/4707774.html
Copyright © 2020-2023  润新知