Incrementing a java.util.Date by one day

前端 未结 8 1054

What is the correct way to increment a java.util.Date by one day.

I\'m thinking something like

        Calendar cal = Calendar.getInstance();
        ca         


        
8条回答
  •  故里飘歌
    2021-02-07 01:46

    Here's how I do it:

    Date someDate = new Date(); // Or whatever    
    Date dayAfter = new Date(someDate.getTime()+(24*60*60*1000));
    

    Where the math at the end converts a day's worth of seconds to milliseconds.

提交回复
热议问题