当前位置:网站首页>2022-06-10 work record --js- obtain the date n days after a certain date
2022-06-10 work record --js- obtain the date n days after a certain date
2022-06-24 22:37:00 【Little radish】
JS- Get to a certain date N Days after
If I have got a date , Then I want to add
7God :
- Implementation method : Convert the currently obtained date to Time stamp , then add
7*24*3600, If it ismillisecond ( The time stamp is 13 position )If you want to3600Back*1000, The results obtained are converted into date .【 This method is provided by the company's excellent brother , Like it by hand 】
Conversion between date and timestamp Check out my other blog :https://blog.csdn.net/weixin_48850734/article/details/124668189
Get to a certain date 7 Days after ️
// Convert date format to timestamp
function timeToTimestamp(time) {
return new Date(time).getTime();
}
// Convert timestamps to date format
function timestampToTime(timestamp) {
let d = new Date((timestamp+'').length==10?timestamp*1000:timestamp);// Timestamp 10 Bitwise demand *1000, Timestamp 13 You don't need to take a seat 1000【(timestamp+'') Express : Convert to string 】
let yyyy = d.getFullYear() + '-'; // year
let MM = (d.getMonth() < 10 ? '0'+(d.getMonth()+1) : (d.getMonth())+1) + '-'; // month (js Get the month in date.getMonth() What you get is 0-11, So we need to +1)
let dd = (d.getDate() < 10 ? '0'+d.getDate() : d.getDate()); // Japan
let h = (d.getHours() < 10 ? '0'+d.getHours() : d.getHours()) + ':'; // Hours
let m = (d.getMinutes() < 10 ? '0'+d.getMinutes() : d.getMinutes()) + ':'; // minute
let s = (d.getSeconds() < 10 ? '0'+d.getSeconds() : d.getSeconds()); // second
return yyyy + MM + dd + ' ' + h + m + s;
}
// Convert the currently acquired date into a timestamp
let curr_timestamp = timeToTimestamp('2022-06-22 14:00:00'); // 1655877600000
// obtain 7 Days after
timestampToTime(curr_timestamp+7*24*3600*1000); // '2022-06-29 14:00:00'
边栏推荐
- Description of software version selection of kt6368a Bluetooth dual-mode transparent chip
- How to compare two or more distributions: a summary of methods from visualization to statistical testing
- ThreadLocal memory leak
- 一个女孩子居然做了十年硬件。。。
- 产业互联网时代,并不存在传统意义上的互联网
- 干货丨产品的可行性分析要从哪几个方面入手?
- Virtual private network foundation
- Embedded development: tips and tricks -- clean jump from boot loader to application code
- A pit in try with resources
- How to extract dates from web pages?
猜你喜欢

无心剑汉英双语诗003. 《书海》

Technology Review: what is the evolution route of container technology? What imagination space is there in the future?

Online filing process

Ansible basic configuration

Docker installs MySQL 8.0. Detailed steps

2022-06-10 工作记录--JS-获取到某一日期N天后的日期

1. fully explain the basic principles of IPSec

try-with-resources 中的一个坑,注意避让

中国SSD行业企业势力全景图

软件设计的七大原则
随机推荐
Principles of Ethernet port mirroring, link aggregation and VLAN Technology
Selection and comparison of message oriented middleware MQ
短视频商城系统,scroll-view如何自适应页面剩余高度
OA system -- save the verification code to session
socket(2)
【软件工程】期末重点
Servlet详解
Industrial development status of virtual human
CDN principle
Certificate photo processing
try-with-resources 中的一个坑,注意避让
Relationnet++: a representation of fusion of multiple detection targets based on transformer | neurips 2020
In the era of full programming, should I give up this road?
NIO、BIO、AIO
L2 元年,Arbitrum Nitro 升级带来更兼容高效的开发体验
In the era of industrial Internet, there is no Internet in the traditional sense
FANUC机器人_KAREL编程入门学习(1)
详细了解关于sentinel的实际应用
Ideal L9, new trend of intelligent cockpit
Visitor tweets tell you which groups are consuming blind boxes