网站首页  汉语字词  英语词汇  考试资料  写作素材  旧版资料

请输入您要查询的范文:

 

标题 javascript获取当前日期所属第几周函数
范文
    javascript获取当前日期所属第几周函数,具体代码如下:
    ////////////////////////////////////////////////////////////////////////////////////////////////////
    //获取当前日期在当前年第几周函数封装,例如2013-08-15 是当前年的第32周
    ////////////////////////////////////////////////////////////////////////////////////////////////////
    function theWeek() {
    var totalDays = 0;
    now = new Date();
    years = now.getYear()
    if (years < 1000)
    years += 1900
    var days = new Array(12);
    days[0] = 31;
    days[2] = 31;
    days[3] = 30;
    days[4] = 31;
    days[5] = 30;
    days[6] = 31;
    days[7] = 31;
    days[8] = 30;
    days[9] = 31;
    days[10] = 30;
    days[11] = 31;
    //判断是否为闰年,针对2月的天数进行计算
    if (Math.round(now.getYear() / 4) == now.getYear() / 4) {
    days[1] = 29
    } else {
    days[1] = 28
    }
    if (now.getMonth() == 0) {
    totalDays = totalDays + now.getDate();
    } else {
    var curMonth = now.getMonth();
    for (var count = 1; count <= curMonth; count++) {
    totalDays = totalDays + days[count - 1];
    }
    totalDays = totalDays + now.getDate();
    }
    //得到第几周
    var week = Math.round(totalDays / 7);
    return week;
    }
随便看

 

在线学习网范文大全提供好词好句、学习总结、工作总结、演讲稿等写作素材及范文模板,是学习及工作的有利工具。

 

Copyright © 2002-2024 cuapp.net All Rights Reserved
更新时间:2025/5/19 10:34:43