JavaScript、翌日の日付を取得する [重複] 質問する

JavaScript、翌日の日付を取得する [重複] 質問する

翌日に返される次のスクリプトがあります:

function today(i)
    {
        var today = new Date();
        var dd = today.getDate()+1;
        var mm = today.getMonth()+1;
        var yyyy = today.getFullYear();

        today = dd+'/'+mm+'/'+yyyy;

        return today;   
    }

これを使用することで:

today.getDate()+1;

私はその月の次の日を取得しています (たとえば、今日は 16 日になります)。

問題は、これが月末になる可能性があり、結局戻ってくることです2014年4月32日

翌日の正確な日付を保証する方法はありますか?

ベストアンサー1

以下を使用できます:

var tomorrow = new Date();
tomorrow.setDate(tomorrow.getDate()+1);

たとえば、4 月は 30 日あるため、次のコードは 5 月 1 日を出力します。

var day = new Date('Apr 30, 2000');
console.log(day); // Apr 30 2000

var nextDay = new Date(day);
nextDay.setDate(day.getDate() + 1);
console.log(nextDay); // May 01 2000    

見るフィドル

おすすめ記事