home
search
help
profile
liking the experience? our app is even better
registration for
employee referral programs
are now open
get referred to google, amazon, flipkart and more
register now  
showing results for get months between two dates java 8
1SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
2		
3Date birth = sdf.parse("2000-01-01");
4Date now = new Date(System.currentTimeMillis());
5		
6Calendar c = Calendar.getInstance();
7c.setTimeInMillis(now.getTime() - birth.getTime());
8int y = c.get(Calendar.YEAR)-1970;
9int m = c.get(Calendar.MONTH);
10int d = c.get(Calendar.DAY_OF_MONTH)-1;
upvote
downvote
source
1LocalDate jamesBirthDay = new LocalDate(1955, 5, 19);
2LocalDate now = new LocalDate(2015, 7, 30);
3        
4int monthsBetween = Months.monthsBetween(jamesBirthDay, now).getMonths();
5int yearsBetween = Years.yearsBetween(jamesBirthDay, now).getYears();
6        
7System.out.println("Month since father of Java born : " 
8                    + monthsBetween);
9System.out.println("Number of years since father of Java born : " 
10                    + yearsBetween);
upvote
downvote
source
1import java.time.*;
2import java.util.*;
3
4public class Exercise1 {  
5   public static void main(String[] args)
6    {
7        LocalDate pdate = LocalDate.of(2012, 01, 01);
8        LocalDate now = LocalDate.now();
9 
10        Period diff = Period.between(pdate, now);
11 
12     System.out.printf("\nDifference is %d years, %d months and %d days old\n\n", 
13                    diff.getYears(), diff.getMonths(), diff.getDays());
14  }
15}
16
17
upvote
downvote
queries leading to this page
find the number of common days between two dates in javajava calculate days between two datescaculate year and month between two dates in javajava difference between two dates in monthshow to calculate the no of days between two dates in javahow to convert a number of days into months 2c weeks and days javacalculate year and month between two dates in javaget days between two dates in javacount months of days in javanumber of months between two dates javajava date difference in monthsjava 8 get how many months lies between two datescalculate number of days between two dates javajava how to calculate how many full months between two datesdifference in months between two dates javahow to find the number of days between two dates in javadifference of month between two dates javacheck if a month and day is between two dates javacompare two months in javafind the number of days between two dates in javajava get years between two datescalculating the number of days between dates javajava get days between two dateshow to calculate number of days between dates in javano of days between two dates in javalist of months between two dates javaconvert years months day to number days in javajava get number of month between 2 dateshow many date in a months javaif i have two different dates having differenet years then how to find months between them in javajava get difference between two monthdays to years and months in javajava get years days difference between two datesget difference in months javacalculate the difference in two dates in terms of month and day in javajava number of days between two dates manuallyhow to get number of months between two dates in javacalculate number of years months and days between two dates in javajava get years days difference between two dates 24 22calculate year and month between two dates in java 22java date time difference in monthslogic to calculate the no of days and months between two dates in javacode to calculate days 2c month and year difference in javahow to get difference days between two dates in javahow to find no of days between two util dates in java 8statistics between months java calculate numberget the number of calendar months between 2 dates in javanumbers of days in months javacalculate number of days between two dates in javaget difference between two dates in years javadifference of time into months in javahow to calculate months between two dates in javajava get days difference between two datesprogram to calculate number of days between two dates in javacalculate no of days between two dates in javacalculate days between two dates in javajava days in number of years 2c months and daysmonths between two dates javacalculate the days 2c years and months between two local dates in javadifference between two dates in years 2c months and days in javajava program to calculate number of days between two datesget number of months between 2 java util datecalculate month and day between two date javafind the number of days between two dates using period in javahow to compare two dates by number of months in javaget number of days between two dates javafind days between two dates javajava calculate months between two datesall months between two dates javanumber of days in a month javajava get number of days between 2 datesnumber of days between two dates javafind months diff between to dates javamonth difference between java datesjava get number of months between two datesjava calculate amount of days in month manuallyjava date difference monthshow to find the days between two dates in javaget number of days between two dates in javajava get 6 months before datecalculate number of years and months between 2 dates in javahow to find no of days between two dates in javajava difference between two dates in years 2c months 2c daysget month difference from two dates in javajava program to find the number of days in a month according to the yearjava get month difference between two datesjava calculate how many days between two dateshow to calculate difference between the year of two dates in javahow to get no of months and days between two dates in javaget the no of days months and years from two dates in javajava months between two datesjava calculate years between two datescount number of months between two dates java how to get the number of days between two days javadate java to two months3 months gap between from date javacount how many months between two dates javaget month difference in long from two dates in javaget all months between two dates javaduration in months javacalculate days between two dates using javafind months between two dates javajava get years between 2 datesmonths between 28 29 javajava calculate amount of days in monthhow to convert days into years months and days in javacalculate number of years and months between these 2 dates in javaget number of months between two dates in java