I have the following code that successfully gets me the difference between two days (in days, hours, minutes, seconds):
SimpleDateFormat format = new SimpleD
While you should use Joda Time simply as a much better date/time API, I suspect the problem is actually just that you're parsing the values incorrectly. Use a format string of:
yyyy-MM-dd HH:mm:ss
... with dd
instead of DD
. The DD
value is "day in year" which I suspect is confusing things, basically overriding the month part entirely. See the SimpleDateFormat documentation for more details.
You can validate what's wrong by printing out d1
and d2
after parsing...