当前位置:网站首页>[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)))
边栏推荐
- Segmenttree
- Installation of torch and torch vision in pytorch
- Grc: personal information protection law, personal privacy, corporate risk compliance governance
- Slow database query optimization
- 【JVM调优实战100例】05——方法区调优实战(下)
- golang中的atomic,以及CAS操作
- Learn self 3D representation like ray tracing ego3rt
- 接收用户输入,身高BMI体重指数检测小业务入门案例
- [Niuke classic question 01] bit operation
- 筑梦数字时代,城链科技战略峰会西安站顺利落幕
猜你喜欢
Lldp compatible CDP function configuration
Anfulai embedded weekly report no. 272: 2022.06.27--2022.07.03
Dell筆記本周期性閃屏故障
资产安全问题或制约加密行业发展 风控+合规成为平台破局关键
Telerik UI 2022 R2 SP1 Retail-Not Crack
界面控件DevExpress WinForms皮肤编辑器的这个补丁,你了解了吗?
[batch dos-cmd command - summary and summary] - string search, search, and filter commands (find, findstr), and the difference and discrimination between find and findstr
【JVM调优实战100例】04——方法区调优实战(上)
Chenglian premium products has completed the first step to enter the international capital market by taking shares in halber international
迈动互联中标北京人寿保险,助推客户提升品牌价值
随机推荐
重上吹麻滩——段芝堂创始人翟立冬游记
Let's talk about 15 data source websites I often use
Grc: personal information protection law, personal privacy, corporate risk compliance governance
斗地主游戏的案例开发
Trace tool for MySQL further implementation plan
[牛客] B-完全平方数
pyflink的安装和测试
tensorflow 1.14指定gpu运行设置
How do novices get started and learn PostgreSQL?
UI control telerik UI for WinForms new theme - vs2022 heuristic theme
Learning notes 5: ram and ROM
Part 7: STM32 serial communication programming
boot - prometheus-push gateway 使用
资产安全问题或制约加密行业发展 风控+合规成为平台破局关键
paddlehub应用出现paddle包报错的问题
深度学习简史(二)
New feature of Oracle 19C: automatic DML redirection of ADG, enhanced read-write separation -- ADG_ REDIRECT_ DML
Data type of pytorch tensor
力扣1037. 有效的回旋镖
Chenglian premium products has completed the first step to enter the international capital market by taking shares in halber international