Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

java number of days between dates

LocalDate start = LocalDate.parse("2020-11-03");
LocalDate end = LocalDate.parse("2020-12-15");

long diff = DAYS.between(start, end);
Comment

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

find number of weeks between two dates in java

SimpleDateFormat myFormat = new SimpleDateFormat("dd MM yyyy");
String classStartData = "31 01 2021";
String classEndData = "08 03 2021";

Date dateClassStart = myFormat.parse(classStartData);
Date dateClassEnd = myFormat.parse(classEndData);

long differenceWeek = dateClassEnd.getTime() - dateClassStart.getTime();
int programLength = (int)(TimeUnit.DAYS.convert(differenceWeek, TimeUnit.MILLISECONDS)/7);
System.out.println("Class length in weeks: " +programLength);
Comment

PREVIOUS NEXT
Code Example
Java :: regex pattern for bank cards validation 
Java :: register watch service java 
Java :: check if first character of a string is a number java 
Java :: convert void * to int 
Java :: runnable java 
Java :: file java class 
Java :: How to efficiently reverse a singly linked list, in Java? 
Java :: abstraction in java 
Java :: java enum 
Java :: how to check if user is logged in firebase android and then load another activity 
Java :: how to turna date into a LocalDateTime java 
Java :: how to add spaces before string in java 
Java :: keytool error: java.lang.Exception: Key pair not generated, alias <demo already exists 
Java :: java print 2d array as table 
Java :: if and else on one line java 
Java :: how to unistall java 
Java :: spring log info 
Java :: throw and throws keyword in java 
Java :: iterate list in java 
Java :: java string vs stringbuilder 
Java :: java get class name of object 
Java :: how to find sum of the digit of the numbers in java 
Java :: android search in webview 
Java :: on item click listener for recyclerview adapter 
Java :: how to create object of abstract class in java 
Java :: currency formatter java 
Java :: how to check duplicate string in java 
Java :: float to int in java 
Java :: array of arrays java 
Java :: new thrad java 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =