Sum two dates in Java

前端 未结 9 690
夕颜
夕颜 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条回答
  •  旧时难觅i
    2020-11-27 08:24

    notnoop answer is definitely correct. However, if you are going to do lots of processing of dates, times and intervals, I suggest that you look at class DateUtils in apache commons lang and at joda-time library.

    JDK7 will come with better support for some of the features that joda-time provides. Just saying ... it might be a consideration if your app makes heavy usage of this stuff.

提交回复
热议问题