Laravel  
laravel
文档
数据库
架构
入门
php技术
    
Laravelphp
laravel / php / java / vue / mysql / linux / python / javascript / html / css / c++ / c#

js date加一天

作者:狂暴的酷   发布日期:2026-04-16   浏览:47

// 获取当前日期并加一天
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 日期

大家都在看

js 数组打乱顺序

js 两个数组取交集

js 数组对象排序

js 对象数组排序

js 数组删掉第一个值

js fill

js 数组连接

js json数组

js 数组复制

js 复制数组

Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3

Laravel 中文站