Answers for "how to compare two dates by number of months in java"

1

how to calculate the amount of months between two dates java

LocalDate jamesBirthDay = new LocalDate(1955, 5, 19);
LocalDate now = new LocalDate(2015, 7, 30);
        
int monthsBetween = Months.monthsBetween(jamesBirthDay, now).getMonths();
int yearsBetween = Years.yearsBetween(jamesBirthDay, now).getYears();
        
System.out.println("Month since father of Java born : " 
                    + monthsBetween);
System.out.println("Number of years since father of Java born : " 
                    + yearsBetween);
Posted by: Guest on November-06-2020
0

java get number of months between two dates

LocalDate currentDay = LocalDate.of(1955, Month.MAY, 19);
		LocalDate desiredDay = LocalDate.now();
		Period age = Period.between(currentDay, desiredDay);
		int years = age.getYears();
		int months = age.getMonths();

		int numberOfMonthsBetweenDates =  months+years*12;
Posted by: Guest on October-01-2020

Code answers related to "how to compare two dates by number of months in java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language