Incrementing a java.util.Date by one day

前端 未结 8 1043

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:59

    Yeah, that's right. Java Date APIs feel wrong quite often. I recommend you try Joda Time. It would be something like:

    DateTime startDate = ...
    DateTime endDate = startDate.plusDays(1);
    

    or:

    Instant start = ...
    Instant end = start.plus(Days.days(1).toStandardDuration());
    

提交回复
热议问题