tl;dr
java.time.Period.between( startLocalDate , stopLocalDate )
java.time
The accepted Answer by Modus Tollens is correct.
FYI, the Joda-Time project is now in maintenance mode, with the team advising migration to the java.time classes. See Tutorial by Oracle.
Here is the modern version of your code.
Parsing your given strings as OffsetDateTime
as they include an offset-from-UTC but not a full time zone.
OffsetDateTime start = OffsetDateTime.parse( "2014-05-28T00:00:00.000+05:30" ) ;
Better to use a time zone than an offset, if known.
ZoneId z = ZoneId.of( "Asia/Kolkata" ) ;
ZonedDateTime start = LocalDate.parse( "2014-05-28" ).atStartOfDay( z ) ;
If your really want to work with a date-only rather than a date-time moment, use the LocalDate
class.
LocalDate start = LocalDate.parse( "2014-05-28" ) ;
You can extract a date-only LocalDate
from either the OffsetDateTime
or ZonedDateTime
by calling toLocalDate
.
Represent the span of time you want to jump, using the Period
class.
Period p = Period.ofMonths( 9 ).plus( Period.ofDays( 12 ) ) ;
Verify that value by generating a string is standard ISO 8601 format.
String pOutput = p.toString() ;
P9M12D
Add the period to the starting date or date-time.
LocalDate later = start.plus( p ) ; // Add the `Period` span-of-time to our starting date.
To calculate elapsed time, use Period.between
.
Period p = Period.between( startLocalDate , stopLocalDate ) ;
About java.time
The java.time framework is built into Java 8 and later. These classes supplant the troublesome old legacy date-time classes such as java.util.Date
, Calendar
, & SimpleDateFormat
.
The Joda-Time project, now in maintenance mode, advises migration to the java.time classes.
To learn more, see the Oracle Tutorial. And search Stack Overflow for many examples and explanations. Specification is JSR 310.
Where to obtain the java.time classes?