当前位置:网站首页>Calculate the number of days from today
Calculate the number of days from today
2022-07-21 02:45:00 【Ziwei front end】
n
Calculate the number of days from today in string representation .
- Use
Date
Constructor to get the current date . - Use
Math.abs()
andDate.prototype.getDate()
Update the date accordingly and use Set as resultDate.prototype.setDate()
. - be used for
Date.prototype.toISOString()
Withyyyy-mm-dd
The format returns a string .
const daysFromNow = n => {
let d = new Date();
d.setDate(d.getDate() + Math.abs(n));
return d.toISOString().split('T')[0];
};
daysFromNow(5); // 2020-10-13 (if current date is 2020-10-08)
边栏推荐
- excel怎么选取特定数字求和?excel选中特定数字求和的方法
- [Android Development iOS Series] Language: SWIFT vs kotlin
- 【SELECT、POLL的缺点,以及EPOLL的优势】
- What is the registration process of website domain name?
- 虚拟主机代理商需要注意什么?
- I have seven schemes to realize web real-time message push, seven!
- Apache Flink 的 YARN Session 提交流程
- A brief introduction to redis, the installation and configuration of redis source code, and the installation and mounting of docker
- 容量调度绝对值配置队列使用与避坑
- swift 使用SMAMB2包,重新打包的心酸历程
猜你喜欢
[Android开发学iOS系列] 语言篇: Swift vs Kotlin
Exploration and practice of dewu app data simulation platform
excel宏被禁用如何启用?excel无法启用宏的解决方法
全栈代码测试覆盖率及用例发现系统的建设和实践
excel怎么选取特定数字求和?excel选中特定数字求和的方法
The beta version of typera is expired and cannot be used normally
Fiddler5+ lightning simulator 4.0 settings for app packet capturing
HMS Core安全检测服务如何帮助大学新生防范电信诈骗?
Binary tree OJ exercise
记录uni-app 打包成apk后获取定位
随机推荐
TCP协议的相关特性
DiFi: A Go-as-You-Pay Wi-Fi Access System 精读笔记(二)
[Android Development iOS Series] Language: SWIFT vs kotlin
China's first white paper on the application of electronic signatures in the construction industry was released
Date range generator
解读Go分布式链路追踪实现原理
分布式笔记(05)— 分布式锁之 etcd(分布式锁原理、etcd特点、分布式锁实现方案)
Buying insight and channel evaluation help optimize marketing decisions
Zhimeng adds a column and prompts "failed to save the catalog data, please check whether there is a problem with your input data" when modifying the column
Jenkins自动化部署
Trax: how to win the sweet war in the summer ice cream market?
老域名建站有什么优势?
一文详解|Go 分布式链路追踪实现原理
RGB dot matrix display based on esp32
虚拟主机代理商需要注意什么?
Introduction, installation and basic use of mongodb database
Binary tree OJ exercise
Excel怎么转换为Word格式?将Excel转换为Word格式的方法
How to set percentage color for Excel data bar? Excel data bar auto fill color by percentage tutorial
Cadisplaylink, nstimer circular reference solution