• C# js获取当前日期为当前月/年/季度的第几周(自然周)


    <script type="text/javascript">

    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, " 周" );

    //今天是当前月的第几周
    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 );
    };

    </script>

  • 相关阅读:
    老调重弹之整除与实数除
    #define 预处理指令(C++,C#,VB.NET)
    char类型和string类型(C++,C#)
    使用XPATH对XML数据进行解析
    SQL Server查询优化之:使用提示(Hints)
    XSLT几种应用场景
    在C++中定义常量的两种方法的比较
    为SSIS编写自定义任务项(Task)之高级篇
    利用反射绑定事件处理程序(C#)
    自定义打开Reflector的方式
  • 原文地址:https://www.cnblogs.com/xinbaba/p/7265096.html
Copyright © 2020-2023  润新知