// 创建一个新的 Date 对象,表示当前日期
let currentDate = new Date();
// 获取当前日期的时间戳(以毫秒为单位)
let currentTime = currentDate.getTime();
// 一天的毫秒数
const oneDayInMillis = 24 * 60 * 60 * 1000;
// 计算加一天后的时间戳
let newTime = currentTime + oneDayInMillis;
// 创建一个新的 Date 对象,表示加一天后的日期
let nextDate = new Date(newTime);
console.log("当前日期: ", currentDate);
console.log("加一天后的日期: ", nextDate);
new Date()
创建一个表示当前日期和时间的 Date
对象。currentDate.getTime()
返回当前日期的时间戳(自1970年1月1日以来的毫秒数)。24 * 60 * 60 * 1000
表示一天的毫秒数。Date
对象,表示加一天后的日期。如果你只需要简单的加一天操作,也可以直接使用 setDate
方法:
let currentDate = new Date();
let nextDate = new Date(currentDate);
nextDate.setDate(currentDate.getDate() + 1);
console.log("当前日期: ", currentDate);
console.log("加一天后的日期: ", nextDate);
这种方式更加简洁,直接通过 setDate
方法修改日期。
上一篇:js 取当前时间
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站