Get the timestamp of the last day of the current day

First get the time object of the last second of the day

getTodayDate(){
    
    
	const year: any = date.getFullYear();
    let month: any = date.getMonth() + 1;
    let strDate: any = date.getDate();
    if (month >= 1 && month <= 9) {
    
    
      month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
    
    
      strDate = "0" + strDate;
    }
    const currentdate = year + '/' + month + '/' + strDate;
}

Because new Date() is used here, the separator between year, month and day is slash /

let todayEnd = getTodayDate() + ' 23:59:59';//其实这里可以获取当前的任意时间点,看需要传
let todayEndObj = new Date(todayEnd);
let todayEndStamp = todayEndObj.getTime();

todayEndStamp is the timestamp of the last second of the day that we need.
In fact, other times can be deduced in the same way:
1. First get the year, month and day we need. The method here is to get the time of any day based on the current day.
2. Then splice the required time point
. 3. Use the new Date() method to convert into a time object
4. Finally call the getTime() method to get any timestamp you want.

Guess you like

Origin blog.csdn.net/be_strong_web/article/details/129562354