当前位置:网站首页>[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)))
边栏推荐
- The difference between spin and sleep
- HMM 笔记
- 接收用户输入,身高BMI体重指数检测小业务入门案例
- from . cv2 import * ImportError: libGL. so. 1: cannot open shared object file: No such file or direc
- [batch dos-cmd command - summary and summary] - string search, search, and filter commands (find, findstr), and the difference and discrimination between find and findstr
- Part V: STM32 system timer and general timer programming
- The printf function is realized through the serial port, and the serial port data reception is realized by interrupt
- 深度学习框架TF安装
- Summary of being a microservice R & D Engineer in the past year
- [牛客] B-完全平方数
猜你喜欢

JTAG principle of arm bare board debugging

Force buckle 1037 Effective boomerang

重上吹麻滩——段芝堂创始人翟立冬游记

Do you understand this patch of the interface control devaxpress WinForms skin editor?

Part IV: STM32 interrupt control programming
![[Niuke] b-complete square](/img/bd/0812b4fb1c4f6217ad5a0f3f3b8d5e.png)
[Niuke] b-complete square

HMM 笔记

「精致店主理人」青年创业孵化营·首期顺德场圆满结束!

Part VI, STM32 pulse width modulation (PWM) programming

ESP Arduino (IV) PWM waveform control output
随机推荐
[牛客] [NOIP2015]跳石头
自旋与sleep的区别
[case sharing] basic function configuration of network loop detection
Atomic in golang, and cas Operations
windows安装mysql8(5分钟)
在jupyter中实现实时协同是一种什么体验
详解OpenCV的矩阵规范化函数normalize()【范围化矩阵的范数或值范围(归一化处理)】,并附NORM_MINMAX情况下的示例代码
What kind of experience is it to realize real-time collaboration in jupyter
深入探索编译插桩技术(四、ASM 探秘)
Force buckle 1037 Effective boomerang
Openjudge noi 1.7 10: simple password
Do you understand this patch of the interface control devaxpress WinForms skin editor?
让我们,从头到尾,通透网络I/O模型
深度学习框架TF安装
Dell筆記本周期性閃屏故障
Cause of handler memory leak
Chapter 5 DML data operation
Dell笔记本周期性闪屏故障
通过串口实现printf函数,中断实现串口数据接收
golang中的atomic,以及CAS操作