当前位置:网站首页>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'
边栏推荐
猜你喜欢
![[personal experiment report]](/img/04/c9e1bee19bff9d55b73c531f7b17f4.png)
[personal experiment report]

一个女孩子居然做了十年硬件。。。

Power system | IEEE paper submission process

Heavyweight! Fada is listed as a "specialized and new" enterprise

MySQL + JSON = King fried!!

Idea close global search box

Zero code can apply data visualization to enterprise management

envoy获取客户端真实IP

DX 的 HLSL 和 GL 的 GLSL的 矩阵构建的行列区别

Technology inventory: past, present and future of Message Oriented Middleware
随机推荐
How does flutter use the online transcoding tool to convert JSON to model
Description of transparent transmission function before master and slave of kt6368a Bluetooth chip, 2.4G frequency hopping automatic connection
CDN principle
Row and column differences in matrix construction of DX HLSL and GL glsl
Cross border e-commerce, early entry and early benefit
How to extract dates from web pages?
【软件工程】期末重点
关于自动控制原理资料更新
What aspects should we start with in the feasibility analysis of dry goods?
Redis-跳表
为什么有的程序员能力一般却能拿到好offer?
详细了解关于sentinel的实际应用
树莓派初步使用
重磅!法大大上榜“专精特新”企业
ansible基本配置
进程的通信方式
Why can some programmers get good offers with average ability?
NIO、BIO、AIO
Development of live broadcast software app, and automatic left-right sliding rotation chart advertising
Certificate photo processing