当前位置:网站首页>[JS] obtain the N days before and after the current time or the n months before and after the current time (hour, minute, second, year, month, day)
[JS] obtain the N days before and after the current time or the n months before and after the current time (hour, minute, second, year, month, day)
2022-07-07 01:10:00 【Cold hope】
There are many ways , But the principle is to obtain the current time first and then add or subtract the time difference
1. Plus or minus timestamp
new Date() You can pass in a timestamp after addition and subtraction
let nowDate = new Date();
// 3 Seconds ago
let nextDate = new Date(nowDate.getTime() - 3 * 1000);
// 3 Minutes ago
let nextDate = new Date(nowDate.getTime() - 3 * 60 * 1000);
// 24 Hours milliseconds
let dayStamp = 24 * 60 * 60 * 1000
// front 1 God
let preDate = new Date(nowDate.getTime() - dayStamp);
// after 3 God
let nextDate = new Date(nowDate.getTime() + 3 * dayStamp);
2.api Set up
Date There are many objects get and set Methods get and set the hour, minute, second, year, day
// 3 Seconds ago
let choiceStartDt = new Date(new Date().setSeconds((new Date().getSeconds() - 3)))
// 7 Seconds later
let choiceStartDt = new Date(new Date().setSeconds((new Date().getSeconds() + 7)))
// 3 Minutes ago
let choiceStartDt = new Date(new Date().setMinutes((new Date().getMinutes() - 3)))
// 3 An hour ago
let choiceStartDt = new Date(new Date().setHours((new Date().getHours() - 3)))
// front 1 God
let choiceStartDt = new Date(new Date().setDate((new Date().getDate() - 1)))
// front 1 Months
let choiceStartDt = new Date(new Date().setMonth((new Date().getMonth() - 1)))
// front 3 year
let choiceStartDt = new Date(new Date().setFullYear((new Date().getFullYear() - 3)))
边栏推荐
- Zabbix 5.0:通过LLD方式自动化监控阿里云RDS
- 新手如何入门学习PostgreSQL?
- Analysis of mutex principle in golang
- 第五篇,STM32系统定时器和通用定时器编程
- 通过串口实现printf函数,中断实现串口数据接收
- Informatics Orsay Ibn YBT 1172: find the factorial of n within 10000 | 1.6 14: find the factorial of n within 10000
- MySQL中回表的代价
- 身体质量指数程序,入门写死的小程序项目
- Batch obtain the latitude coordinates of all administrative regions in China (to the county level)
- Learn self 3D representation like ray tracing ego3rt
猜你喜欢
Trace tool for MySQL further implementation plan
Deeply explore the compilation and pile insertion technology (IV. ASM exploration)
【案例分享】网络环路检测基本功能配置
力扣1037. 有效的回旋镖
Data type of pytorch tensor
pyflink的安装和测试
阿里云中mysql数据库被攻击了,最终数据找回来了
详解OpenCV的矩阵规范化函数normalize()【范围化矩阵的范数或值范围(归一化处理)】,并附NORM_MINMAX情况下的示例代码
ARM裸板调试之JTAG调试体验
Installation and testing of pyflink
随机推荐
ARM裸板调试之JTAG调试体验
Grc: personal information protection law, personal privacy, corporate risk compliance governance
JTAG debugging experience of arm bare board debugging
【批處理DOS-CMD命令-匯總和小結】-字符串搜索、查找、篩選命令(find、findstr),Find和findstr的區別和辨析
paddlehub应用出现paddle包报错的问题
Atomic in golang and CAS operations
mysql: error while loading shared libraries: libtinfo. so. 5: cannot open shared object file: No such
Batch obtain the latitude coordinates of all administrative regions in China (to the county level)
[Niuke classic question 01] bit operation
pytorch之数据类型tensor
from . cv2 import * ImportError: libGL. so. 1: cannot open shared object file: No such file or direc
筑梦数字时代,城链科技战略峰会西安站顺利落幕
[牛客] [NOIP2015]跳石头
C9 colleges and universities, doctoral students make a statement of nature!
golang中的atomic,以及CAS操作
NEON优化:性能优化经验总结
Pytorch中torch和torchvision的安装
接收用户输入,身高BMI体重指数检测小业务入门案例
实现mysql与ES的增量数据同步
Activereportsjs 3.1 Chinese version | | | activereportsjs 3.1 English version