惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Engineering at Meta
Engineering at Meta
Cloudbric
Cloudbric
云风的 BLOG
云风的 BLOG
A
About on SuperTechFans
The GitHub Blog
The GitHub Blog
IT之家
IT之家
F
Full Disclosure
B
Blog RSS Feed
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Hugging Face - Blog
Hugging Face - Blog
B
Blog
H
Help Net Security
The Cloudflare Blog
Recorded Future
Recorded Future
P
Proofpoint News Feed
P
Proofpoint News Feed
C
Cisco Blogs
T
Tailwind CSS Blog
P
Palo Alto Networks Blog
D
Docker
爱范儿
爱范儿
Know Your Adversary
Know Your Adversary
博客园 - 聂微东
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Y
Y Combinator Blog
雷峰网
雷峰网
AWS News Blog
AWS News Blog
D
DataBreaches.Net
博客园 - 司徒正美
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
博客园 - Franky
C
Cybersecurity and Infrastructure Security Agency CISA
Blog — PlanetScale
Blog — PlanetScale
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Latest news
Latest news
Google DeepMind News
Google DeepMind News
Martin Fowler
Martin Fowler
MongoDB | Blog
MongoDB | Blog
C
CERT Recently Published Vulnerability Notes
阮一峰的网络日志
阮一峰的网络日志
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
C
CXSECURITY Database RSS Feed - CXSecurity.com
酷 壳 – CoolShell
酷 壳 – CoolShell
C
Cyber Attacks, Cyber Crime and Cyber Security
腾讯CDC
小众软件
小众软件
G
Google Developers Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
Scott Helme
Scott Helme
O
OpenAI News

博客园 - 猫狼

安卓连接usb camera 安卓手机连接USB摄像头代码 安装Memurai 把“休眠”功能找回来,并设置成一合上盖子就生效 mathtype安装后在office无法启动,提示运行时错误53, 文件未找到:MathPage.WLL ASP.NET Web Site Project 中集成 Hangfire 并实现图片/视频压缩后台任务 SQL SERVER 数据库压缩日志步骤 Latex的一个错误, SQL 学习笔记 升级 ASP.NET 网站项目到 C# 6.0 或更高版本 C#程序集合并工具-ILRepack manim 安装 manim一个坑爸爸的问题 manim安装纪实 去掉快捷方式的小箭头 VS2022转到定义功能异常解决方案 url 传递加号,asp.net解析参数的正确处理参数 移出Json对象的三级属性 梦记:又要去交流? 一段VBA的代码,到处是坑 多个AJAX请求,带执行进度及结果 C# 返回文件夹及子目录 解决JS跨域访问的问题 利用Jquery的map函数将json数据行转化为表格 模访京东商城jQuery省市区三级联动选择(横向DIV)
获取自然周数的下拉列表
猫狼 · 2024-08-04 · via 博客园 - 猫狼

需要引用第三方的day.js库,设定了只显示过去60天的周数,可自行修改

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>自然周数下拉列表</title>
    <script src="/js/day.1.11.12.js"></script>
</head>
<body>
<select id="ddlWeeks"></select>
<script>
    function getWeekNumber(date) {
        var d = new Date(date);
        d.setHours(0, 0, 0);
        d.setDate(d.getDate() + 4 - (d.getDay() || 7));
        var yearStart = new Date(d.getFullYear(), 0, 1);
        var weekNo = Math.ceil(((d - yearStart) / 86400000) / 7);
        return weekNo;
    }
    function populateWeekDropdown(year) {
        var select = document.getElementById('ddlWeeks');
        var numWeeks = new Date(year, 11, 31).getDay() === 4 || new Date(year, 11, 31).getDay() === 5 ? 54 : 53;
        for (var i = 1; i <= numWeeks; i++) {
            var weekNumber = i < 10 ? '0' + i : i;
            var start_end = getWeekStartAndEndDate(year, weekNumber);
            var start = start_end.start;
            var end = start_end.end;
            if (daysBetween(start, new Date()) > 60) {
                continue;
            }
            var option = document.createElement('option');
            option.value = dayjs(start).format("YYYY-MM-DD");//year + 'W' + weekNumber;
            option.text = weekNumber + "周:" + dayjs(start).format("YY-MM-DD");
            select.appendChild(option);
            if (end > new Date()) {
                break;
            }
        }
    }

    function daysBetween(date1, date2) {
        const oneDay = 86400000; // 一天的毫秒数
        const date1Ms = date1.getTime(); // 将日期转换为时间戳
        const date2Ms = date2.getTime(); // 同上
        // 计算两个日期之间相差的毫秒数
        const diff = Math.abs(date1Ms - date2Ms); 
        // 将毫秒数转换为天数
        return Math.round(diff / oneDay); 
    }

    function getWeekStartAndEndDate(year, weekNumber) {
        const date = new Date(year, 0, 1); // 获取该年份的第一天
        const dayOfWeek = date.getDay() || 7; // 获取第一天是星期几(‌周日为7,‌周一为1,‌以此类推)‌
        const offset = date.getDate() - dayOfWeek + (weekNumber - 1) * 7 + 1; // 计算该周第一天的日期偏移量
        const start = new Date(date.setDate(offset)); // 设置起始日期
        const end = new Date(start); // 复制起始日期对象
        end.setDate(start.getDate() + 6); // 设置结束日期为起始日期加6天
        return { start, end };
    }


    var currentYear = new Date().getFullYear();
    var curMonth = new Date().getMonth();
    if (curMonth <= 1) {
        populateWeekDropdown(currentYear - 1);
    }
    populateWeekDropdown(currentYear);
</script>

</body>
</html>