Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

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);
Comment

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;
Comment

calculate number of years months and days between two dates in java

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		
Date birth = sdf.parse("2000-01-01");
Date now = new Date(System.currentTimeMillis());
		
Calendar c = Calendar.getInstance();
c.setTimeInMillis(now.getTime() - birth.getTime());
int y = c.get(Calendar.YEAR)-1970;
int m = c.get(Calendar.MONTH);
int d = c.get(Calendar.DAY_OF_MONTH)-1;
Comment

PREVIOUS NEXT
Code Example
Java :: link to method javadoc 
Java :: create method setsupportactionbar 
Java :: joptionpane 
Java :: convert int to double with 2 decimal places java 
Java :: java get ip address 
Java :: Unrecognized option: --version Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit. 
Java :: ripple effect textview android 
Java :: java shutdown hook 
Java :: kill all java processes linux 
Java :: scanner check if int 
Java :: java jpa criteriabuilder in xample 
Java :: Java Hashmap Access Elements 
Java :: java convert integer to string 
Java :: how to check whether a character is vowel in java 
Java :: android studio remove action bar 
Java :: java xmx example 
Java :: how to add elements to an array in java dynamically 
Java :: java foreach 
Java :: findviewbyid java android 
Java :: RecyclerView: No layout manager attached; skipping layout 
Java :: java scanner netLine 
Java :: valueof vs tostring 
Java :: recycler view implementation 
Java :: android checkbox tint color 
Java :: set remove element java 
Java :: java logger 
Java :: java max int value 
Java :: How to count the number of islands (groups of adjacent 1s) in a grid of 1s (land) and 0s (water), in Java? 
Java :: java camel case 
Java :: eclipse java content assist 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =