How do I convert given days into Calendar format in java.
Example Initial date is 01-01-2015. Given days are 125 days. This should be converted as 0 years, 4 months, 5 days and added to initial date which would become 06-05-2015.
How do I convert given days into Calendar format in java.
Example Initial date is 01-01-2015. Given days are 125 days. This should be converted as 0 years, 4 months, 5 days and added to initial date which would become 06-05-2015.
You can use Period
class from java8's new java.time
API to convert the difference between two dates into years, months and days:
LocalDate initial = LocalDate.of(2015, 1, 1);
LocalDate end = initial.plusDays(125);
Period p = Period.between(initial, end);
int years = p.getYears(); // 0
int months = p.getMonths(); // 4
int days = p.getDays(); // 5