js获取当前日期一年的第几周

获取当前日期一年中的第几周

复制代码
 1     function theWeek() {
 2         var totalDays = 0;
 3         now = new Date();
 4         years = now.getYear()
 5         if (years < 1000)
 6             years += 1900
 7         var days = new Array(12);
 8         days[0] = 31;
 9         days[2] = 31;
10         days[3] = 30;
11         days[4] = 31;
12         days[5] = 30;
13         days[6] = 31;
14         days[7] = 31;
15         days[8] = 30;
16         days[9] = 31;
17         days[10] = 30;
18         days[11] = 31;
19         //判断是否为闰年,针对2月的天数进行计算
20         if (Math.round(now.getYear() / 4) == now.getYear() / 4) {
21             days[1] = 29
22         } else {
23             days[1] = 28
24         }
25         if (now.getMonth() == 0) {
26             totalDays = totalDays + now.getDate();
27         } else {
28             var curMonth = now.getMonth();
29             for (var count = 1; count <= curMonth; count++) {
30                 totalDays = totalDays + days[count - 1];
31             }
32             totalDays = totalDays + now.getDate();
33         }
34         //得到第几周
35         var week = Math.round(totalDays / 7);
36         return week;
37     }
复制代码
posted @   陈彦斌  阅读(3583)  评论(0编辑  收藏  举报
编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
主题色彩
点击右上角即可分享
微信分享提示