当前位置:网站首页>返回日期对应的一年中的第几周
返回日期对应的一年中的第几周
2022-07-20 04:08:00 【紫微前端】
返回日期对应的一年中的零索引周。
- 使用
Date
构造函数并Date.prototype.getFullYear()
获取一年中的第一天作为Date
对象。 - 使用
Date.prototype.setDate()
,Date.prototype.getDate()
并Date.prototype.getDay()
与模 (%
) 运算符一起获取一年中的第一个星期一。 - 从给定值中减去一年中的第一个星期一,
date
然后除以一周中的毫秒数。 - 用于
Math.round()
获取对应于给定 的一年中的零索引周date
。 -0
如果给定date
在一年的第一个星期一之前,则返回。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
边栏推荐
- 大佬们问个问题,flinksql写入mysql,非空字段写入不进去,报我没给默认值咋回事,有大佬看看
- [upload range 12-16] cut, picture horse
- 返回给定日期月份中最后一个日期的字符串表示形式
- Leetcode sword finger offer 32 - I. print binary tree from top to bottom
- Locking is familiar with synchronized and lock, so what is the difference between them
- EXCEL的去重去除某个字段后全部操作
- Caffeine缓存增改查过期
- exness:美元温和回落,澳洲联储呼吁进一步加息
- 从功能到测开,阿里巴巴软件测试面经,看看大厂的技术栈
- 给家长的手机补修课
猜你喜欢
动态内存管理
Wave field joint reserve issued an open letter, emphasizing that usdd is not subject to any centralized institutions
Ppt concise
Shengsi YiDianTong | deep learning analysis of classical convolutional neural network
redis分布式锁+线程池
[special for training course] Introduction to storage API
ECs and cloud database management
机器学习笔记: ELMO BERT
《暴走 IT》第1话:来了个新同事
目标检测的类别损失和位置损失
随机推荐
详解激活函数
推荐一个截图工具-Snipaste
The difference between break, continue and return
Introduction to target detection (up to 2020)
[pytoch] tensorboard usage: scalar curve, histogram, model structure diagram
Explain fcos: full revolutionary one stage object detection in detail
5G时代到来,VR全景制作是值得创业的行业
存储过程和for循环插入数据
Exness: the dollar fell moderately, and the RBA called for further interest rate hikes
Shengteng AI innovation competition | Shengsi track live training, the guide for obtaining up to 10million bonuses is coming
href和src、div和span的区别
35- [go] reflection of golang
【Pytorch】Tensorboard用法:标量曲线图、直方图、模型结构图
何为整型提升(实例)
BOM浏览器对象模型(下篇)—— offset、client、scroll三大家族、插件及本地存储特性(案例:仿京东放大镜、模态框拖拽)
[special for training course] Introduction to storage API
Differences between href and SRC, div and span
Redefine analysis - release of eventbridge real-time event analysis platform
C language file management function and principle
Locking is familiar with synchronized and lock, so what is the difference between them