// 获取当前日期并加一天
function addOneDayToDate(date) {
// 创建一个新的 Date 对象,参数为传入的 date
const newDate = new Date(date);
// 使用 setDate 方法将日期增加一天
newDate.setDate(newDate.getDate() + 1);
// 返回新的日期
return newDate;
}
// 示例用法
const today = new Date(); // 获取当前日期
const tomorrow = addOneDayToDate(today); // 加一天后的日期
console.log("今天的日期是: " + today);
console.log("明天的日期是: " + tomorrow);
new Date(date):创建一个新的 Date 对象,基于传入的 date。newDate.setDate(newDate.getDate() + 1):使用 setDate 方法将日期增加一天。getDate() 获取当前日期的天数,然后加上 1。addOneDayToDate 函数接收一个 Date 对象作为参数,并返回一个新的 Date 对象,表示原日期加一天后的日期。今天的日期是: Thu Oct 12 2023 15:30:45 GMT+0800 (中国标准时间)
明天的日期是: Fri Oct 13 2023 15:30:45 GMT+0800 (中国标准时间)
上一篇:js 日期加一个月
下一篇:js 日期
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站