当前位置:网站首页>计算从今天开始的天数
计算从今天开始的天数
2022-07-20 04:08:00 【紫微前端】
n
以字符串表示形式计算从今天开始的天数。
- 使用
Date
构造函数获取当前日期。 - 使用
Math.abs()
和Date.prototype.getDate()
相应地更新日期并使用 设置为结果Date.prototype.setDate()
。 - 用于
Date.prototype.toISOString()
以yyyy-mm-dd
格式返回字符串。
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)
边栏推荐
- 高并发之使用RateLimiter、Semaphore对访问资源进行限流
- 【Pytorch】Tensorboard用法:标量曲线图、直方图、模型结构图
- [pytoch] tensorboard usage: scalar curve, histogram, model structure diagram
- Idea activation
- From function to test open, Alibaba software testing experience, look at the technology stack of big manufacturers
- Caffeine缓存增改查过期
- Wave field joint reserve issued an open letter, emphasizing that usdd is not subject to any centralized institutions
- 基于ESP32的RGB点阵显示器
- 目标检测的进阶-one stage
- 進程和線程
猜你喜欢
数据可视化之堆叠柱状图带你了解宠物数据
EXCEL的去重去除某个字段后全部操作
推荐一个截图工具-Snipaste
ResNet知识点补充
Shengsi YiDianTong | deep learning analysis of classical convolutional neural network
Use ECs and OSS to set up personal network disk
简略break、continue、return的区别
ROS (sub, pub) test plotjuggler
Exness: the dollar fell moderately, and the RBA called for further interest rate hikes
Redis application
随机推荐
BN与LN的区别
动画函数封装(缓动动画)
DP knapsack problem
Method of creating thread
给家长的手机补修课
Leetcode sword finger offer 11 Rotate the minimum number of the array
This beta version of Typora is expired,please download and install a newer version.
一文速学-PySpark数据分析基础:PySpark基础功能及基础语法详解
Will the expired data of redis be deleted immediately?
Category loss and location loss of target detection
BOM浏览器对象模型(上篇)——概述、window对象常见事件、JS执行机制(5秒后关闭广告、倒计时案例、发送短信倒计时案例)
创建线程的方法
Wave field joint reserve issued an open letter, emphasizing that usdd is not subject to any centralized institutions
特殊类的设计(单例模式)
Records from July 18, 2022 to July 25, 2022
添加给定的工作日数后计算日期
36- [go] IO stream of golang
目标检测的进阶-one stage
Redis 的过期数据会被立马删除么?
高并发之使用RateLimiter、Semaphore对访问资源进行限流