当前位置:网站首页>The week of the year corresponding to the return date
The week of the year corresponding to the return date
2022-07-21 02:45:00 【Ziwei front end】
Returns the zero index week of the year corresponding to the date .
- Use
Date
Constructor andDate.prototype.getFullYear()
Get the first day of the year asDate
object . - Use
Date.prototype.setDate()
,Date.prototype.getDate()
andDate.prototype.getDay()
And mold (%
) Operator to get the first Monday of the year . - Subtract the first Monday of the year from the given value ,
date
Then divide by the number of milliseconds in a week . - be used for
Math.round()
Get corresponding to the given Zero index week of the yeardate
. -0
If a givendate
Before the first Monday of the year , Then return to .const weekOfYear = date => { const startOfYear = new Date(date.getFullYear(), 0, 1); startOfYear.setDate(startOfYear.getDate() + (startOfYear.getDay() % 7)); return Math.round((date - startOfYear) / (7 * 24 * 3600 * 1000)); }; weekOfYear(new Date('2021-06-18')); // 23
边栏推荐
- [advanced C language] - detailed explanation of user-defined types
- 爱学啊的博客-人生苦短,只做好课!
- How does excel choose specific numbers to sum? Excel method of selecting specific numbers for summation
- Trax: how to win the sweet war in the summer ice cream market?
- Can the tidb of a single machine be used in the production environment?
- 织梦DEDE后台系统用户管理显示空白的解决方法
- AI2 (APP inventor 2) offline version
- Real time debugging practice based on attach to process
- Analysis on the wallet system architecture of Baidu trading platform
- excel宏被禁用如何启用?excel无法启用宏的解决方法
猜你喜欢
软件测试职业发展方向(不要迷茫了,赶紧卷起来)
[Muduo socket] InetAddress encapsulates the socket address type
What is Excel Macro? Tutorial on using Excel macros
MongoDB数据库简介、安装和基本使用
excel怎么选取特定数字求和?excel选中特定数字求和的方法
在线问题反馈模块实战(八):实现图片上传功能(上)
Office软件无法正常启动0xc0000142怎么解决?
【SELECT、POLL的缺点,以及EPOLL的优势】
Kingdee's "answer sheet" forecast in the first half of the year: key customer strategy continued to break through, and arr increased by more than 45% year-on-year
[Android開發學iOS系列] 語言篇: Swift vs Kotlin
随机推荐
Huawei's general card identification function enables multiple card bindings with one key
vivo官网APP全机型UI适配方案
apple 为什么要改 objc
How to set percentage color for Excel data bar? Excel data bar auto fill color by percentage tutorial
Dynamic memory management
结构体完结(柔性数组)
MongoDB数据库简介、安装和基本使用
How to convert Excel to word format? Method of converting Excel to word format
Trax: how to win the sweet war in the summer ice cream market?
华为通用卡证识别功能,一键实现多种卡绑定
Excel如何进行多条件查找?Excel多条件查找函数的方法汇总
Alibaba cloud international account registration FAQ summary
NFT潮鞋AR互动零基础教程来啦!
无密码身份验证如何保障用户隐私安全?
计算从今天开始的天数
Kingdee's "answer sheet" forecast in the first half of the year: key customer strategy continued to break through, and arr increased by more than 45% year-on-year
fiddler5+雷电模拟器4.0对app抓包设置
gerrit系统如何配置访问控制
PPT柱状图如何增加柱子
[Muduo socket] InetAddress encapsulates the socket address type