Unclear question
You do not provide actual values, so we cannot pinpoint the problem. We do not know what the variables todayand represent dueDate.
, , java.util.Date/.Calendar, java.time. . Tutorial. JSR 310, Joda-Time ThreeTen-Extra.
java.time:
- An
Instant - UTC. - A
ZoneId . , 3-4 , "EST" "IST", . - ,
ZonedDateTime= + ZoneId.
ThreeTen-Extra
, java.time , . ThreeTen-Extra Days class between, . ThreeTen-Extra , java.time JSR.
ZoneId zoneId = ZoneId.of ( "America/Montreal" );
ZonedDateTime now = ZonedDateTime.now ( zoneId );
ZonedDateTime then = now.minusDays ( 4 );
ZonedDateTime due = now.plusDays ( 3 );
Integer days = org.threeten.extra.Days.between ( then , due ).getAmount ();
.
System.out.println ( "From then: " + then + " to due: " + due + " = days: " + days );
: 2015-10-31T16: 01:13.082-04: 00 [/] : 2015-11-07T16: 01:13.082-05: 00 [/] = : 7
Joda
Android Java Joda-Time.
Days , Daylight (DST).
, java.util.Date Joda-Time DateTime .
DateTimeZone timeZone = DateTimeZone.forID( "America/Regina" );
DateTime now = new DateTime( timeZone );
DateTime startOfToday = now.withTimeAtStartOfDay();
DateTime fewDaysFromNow = now.plusDays( 3 );
DateTime startOfAnotherDay = fewDaysFromNow.withTimeAtStartOfDay();
Days days = Days.daysBetween( startOfToday, startOfAnotherDay );
...
System.out.println( days.getDays() + " days between " + startOfToday + " and " + startOfAnotherDay + "." );
...
3 days between 2014-01-21T00:00:00.000-06:00 and 2014-01-24T00:00:00.000-06:00.