当前位置:网站首页>[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)))
边栏推荐
- Come on, don't spread it out. Fashion cloud secretly takes you to collect "cloud" wool, and then secretly builds a personal website to be the king of scrolls, hehe
- NEON优化:性能优化常见问题QA
- Batch obtain the latitude coordinates of all administrative regions in China (to the county level)
- [牛客] [NOIP2015]跳石头
- Installation and testing of pyflink
- 第四篇,STM32中断控制编程
- Configuring OSPF basic functions for Huawei devices
- JTAG debugging experience of arm bare board debugging
- SuperSocket 1.6 创建一个简易的报文长度在头部的Socket服务器
- 「笔记」折半搜索(Meet in the Middle)
猜你喜欢
View remote test data and records anytime, anywhere -- ipehub2 and ipemotion app
ESP Arduino (IV) PWM waveform control output
[Batch dos - cmd Command - Summary and Summary] - String search, find, Filter Commands (FIND, findstr), differentiation and Analysis of Find and findstr
动态规划思想《从入门到放弃》
Segmenttree
Chenglian premium products has completed the first step to enter the international capital market by taking shares in halber international
Part 7: STM32 serial communication programming
ARM裸板调试之JTAG原理
让我们,从头到尾,通透网络I/O模型
UI control telerik UI for WinForms new theme - vs2022 heuristic theme
随机推荐
第五篇,STM32系统定时器和通用定时器编程
迈动互联中标北京人寿保险,助推客户提升品牌价值
[Niuke classic question 01] bit operation
Anfulai embedded weekly report no. 272: 2022.06.27--2022.07.03
gnet: 一个轻量级且高性能的 Go 网络框架 使用笔记
一行代码实现地址信息解析
windows安装mysql8(5分钟)
NEON优化:关于交叉存取与反向交叉存取
How do novices get started and learn PostgreSQL?
[100 cases of JVM tuning practice] 05 - Method area tuning practice (Part 2)
golang中的Mutex原理解析
NEON优化:矩阵转置的指令优化案例
Oracle:CDB限制PDB资源实战
【js】获取当前时间的前后n天或前后n个月(时分秒年月日都可)
Link sharing of STM32 development materials
[software reverse - solve flag] memory acquisition, inverse transformation operation, linear transformation, constraint solving
Force buckle 1037 Effective boomerang
C# 计算农历日期方法 2022
Informatics Olympiad YBT 1171: factors of large integers | 1.6 13: factors of large integers
[HFCTF2020]BabyUpload session解析引擎