计算当前日期是今年第几周的JS代码封装
2017-01-26 12:48
459 查看
最近身边的人有做一个项目, 然后里面有个小模块, 需要作出如下图所示的效果:
一个下拉框, 然后里面有显示日期已经今年的第几周的这样一个效果, 具体完整的流程我暂时还没想到, 但是找到了一个能够算出当前系统日期是今年的第几周的一个封装好的方法, 如下所示:
}
一个下拉框, 然后里面有显示日期已经今年的第几周的这样一个效果, 具体完整的流程我暂时还没想到, 但是找到了一个能够算出当前系统日期是今年的第几周的一个封装好的方法, 如下所示:
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;
}
相关文章推荐
- C#计算当前日期为一年中的第几周
- java计算当前月的第几周,及周的起止日期/月及月的起止日期
- 计算当前日期是任意时间段内第几周的函数
- 根据日期计算当前日期所在周是日期所在年份的第几周
- 开学时间为2009年2月18日,计算当前日期是第几周
- 计算当前日期是本年的第几周
- 计算当前日期是一年中的第几周
- 计算当前日期是任意时间段内第几周的函数
- 计算当前日期是任意时间段内第几周的函数
- Android 当前日期,计算时间推后几天和提前几天的封装方法
- c#获取当前日期是今年第几周
- 计算当前日期是本年度的第几周
- 计算当前日期是当年第几周的函数
- C#中怎么计算当前日期是在一年中的第几周
- [转]C#中怎么计算当前日期是在一年中的第几周
- Js获取当前日期及计算当前日期是今年的第多少天
- c#获取当前日期是今年第几周
- 如何计算当前日期是当年的第几周?
- Domino计算当前日期是这一年的第几周,以及计算任意一周都分别是哪七天?
- JavaScript 计算当前日期是本年度及本月度第几周