JavaScript gets the start time and end time of the day

1. Get the start time of the day

const startTime = new Date(new Date(new Date().toLocaleDateString()).getTime());
console.log(startTime);
// Fri Nov 12 2021 00:00:00 GMT+0800 (中国标准时间)

2. Get the end time of the day

let endTime = new Date(new Date(new Date().toLocaleDateString()).getTime() + 24 * 60 * 60 * 1000 - 1);
console.log(endTime);
// Fri Nov 12 2021 23:59:59 GMT+0800 (中国标准时间)

Guess you like

Origin blog.csdn.net/m0_61672533/article/details/128217890