// Format date :yyyy-MM-dd
function formatDate(date) {
var myyear = date.getFullYear();
var mymonth = date.getMonth() + 1;
var myweekday = date.getDate();
if (mymonth < 10) {
mymonth = "0" + mymonth;
}
if (myweekday < 10) {
myweekday = "0" + myweekday;
}
return (myyear + "-" + mymonth + "-" + myweekday);
}
//
function getXDate(year, weeks, weekDay) {
weekDay %= 7;
var date = new Date(year, "0", "1");
var time = date.getTime();
weekDay == 0 ? time += weeks * 7 * 24 * 3600000 : time += (weeks - 1) * 7 * 24 * 3600000;// Here we need to pay attention to , Now this mode ends on Sunday , If you set Sunday as the beginning of the week , Remove this judgment , Choose the latter .
date.setTime(time);
return getNextDate(date, weekDay);
}
function getNextDate(nowDate, weekDay) {
var day = nowDate.getDay();
var time = nowDate.getTime();
var sub = weekDay - day;
time += sub * 24 * 3600000;
nowDate.setTime(time);
return nowDate;
}
// Be careful , The parameters are : The first is year , The second is the week , The third is the number of weeks ,0 It's Sunday ,1 For Monday ;
alert("1983 The first 1 Week of week 1 yes :" + formatDate(getXDate(1983, 1, 1)));
alert("1983 The first 1 The Sunday of the week is :" + formatDate(getXDate(1983, 1, 0)));
当前位置:网站首页>JS get the start and end dates of this week according to the nth week of the N year
JS get the start and end dates of this week according to the nth week of the N year
2022-06-12 18:30:00 【Front end cute】
边栏推荐
- C#的变量
- 309. the best time to buy and sell stocks includes the freezing period
- Title 37: sorting 10 numbers
- Interior design style type, rendering 100 invitation code [1a12]
- 【sql语句基础】——查(select)(单表查询)
- C brief introduction
- Gospel of audio and video developers, rapid integration of AI dubbing capability
- 从源码解析 MobX 响应式刷新机制
- Title 54: take 4 ~ 7 bits of an integer a from the right end.
- 用grep awk提取字符串
猜你喜欢

Review of MySQL (3): query operation

VirtualLab基礎實驗教程-4.單縫衍射

"Big fat • small lesson" - talk about big file segmentation and breakpoint sequel

MYSQL:Expression #4 of SELECT list is not in GROUP BY clause and contains nonaggregated column

Introduction to reinforcement learning and analysis of classic items 1.3

Machine learning series (3): logistic regression

Variable of C #

Review of MySQL (V): Joint table query and sub query

Global lock, table lock, row lock

USB转串口那些事儿—最大峰值串口波特率VS连续通信最高波特率
随机推荐
01 complexity
Analyzing mobx responsive refresh mechanism from source code
js二分法
Gd32f4xx controls dgus touch keys
Review of MySQL (IX): index
迄今微软不同时期发布的SQL Server各版本之间的大致区别,供参考查阅
Gd32f4xx controls dgus variable display
01-复杂度
Summary of interview questions
C language practice (4) -- multiplication and division of large numbers
Introduction to reinforcement learning and analysis of classic items 1.3
VirtualLab基础实验教程-6.闪耀光栅
从源码解析 MobX 响应式刷新机制
Review of MySQL (VI): usage of Union and limit
Machine learning series (3): logistic regression
JS sum of two numbers
LCD parameter interpretation and calculation
Comparison of disk mapping tools for network disk and object cloud storage management
Typescript advanced type (2)
Global lock, table lock, row lock