java - Period.between only subtracting days -
java - Period.between only subtracting days -
the variable datesubtract comes out 16 want find total number of days in between 2 days, should 165. how can without joda time?
string date = "06/17/2014"; datetimeformatter formatter = datetimeformatter.ofpattern("mm/dd/yyyy"); localdate d1 = localdate.parse("01/01/2014", formatter); localdate d2 = localdate.parse(date, formatter); int datesubtract = period.between(d1, d2).getdays();
period combination of day, month, year. in case, period 5 months , 16 days. explained in javadoc although not clear if read casually.
the days unit not automatically normalized months , years unit. means period of "45 days" different period of "1 month , 15 days" , getdays() homecoming 45 , 15 respectively.
to total number of days between 2 dates, can use:
//including d1, excluding d2: chronounit.days.between(d1, d2); //or, exclude d1 , d2, 1 of these: chronounit.days.between(d1.plusdays(1), d2); chronounit.days.between(d1, d2) - 1; java datetime-format period
Comments
Post a Comment