Sum two dates in Java

前端 未结 9 664
夕颜
夕颜 2020-11-27 07:47

How can I add two dates in Java?

Example: The sum of \"2010-01-14 19:16:17\" \"0000-10-03 01:10:05\"
would result in \"2010-11-17 20:26:22\".

I know how

9条回答
  •  执笔经年
    2020-11-27 08:24

    Use calendar class add method to add two dates in java.

    Calendar calendar=Calendar.getInstance();
    
    calendar.add(Calendar.Date,23);
    
    calendar.add(Calendar.Month,13);
    
    calendar.add(Calendar.Year,15);
    

    By using add method in Calendar class we can add day,month,year to the existing date.

    click here for complete program.

提交回复
热议问题