js当前日期的后一天0点24点
时间: 2023-06-25 19:04:49 浏览: 70
可以使用 JavaScript 中的 Date 对象来实现。首先获取当前日期,然后使用 `setDate` 方法将日期加一天,最后分别设置小时、分钟、秒和毫秒为 0 和 23:59:59.999。具体代码如下:
```js
// 获取当前日期
const currentDate = new Date();
// 将日期加一天
currentDate.setDate(currentDate.getDate() + 1);
// 设置小时、分钟、秒和毫秒为 0
currentDate.setHours(0, 0, 0, 0);
// 获取后一天的 0 点
const nextDayStart = currentDate.getTime();
// 设置小时、分钟、秒和毫秒为 23:59:59.999
currentDate.setHours(23, 59, 59, 999);
// 获取后一天的 24 点
const nextDayEnd = currentDate.getTime();
// 输出结果
console.log(new Date(nextDayStart)); // 后一天的 0 点
console.log(new Date(nextDayEnd)); // 后一天的 24 点
```
这样就可以得到当前日期的后一天的 0 点和 24 点的时间戳。如果需要输出格式化后的日期字符串,可以使用 `toLocaleString` 方法进行格式化。例如:
```js
console.log(new Date(nextDayStart).toLocaleString()); // 输出格式化后的日期字符串
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)