calculate days between two dates in java
Java
import java.util.Date;
import java.text.SimpleDateFormat;
class Example{
public static void main(String args[]){
SimpleDateFormat myFormat = new SimpleDateFormat("dd MM yyyy");
String dateBeforeString = "31 01 2014";
String dateAfterString = "02 02 2014";
try {
Date dateBefore = myFormat.parse(dateBeforeString);
Date dateAfter = myFormat.parse(dateAfterString);
long difference = dateAfter.getTime() - dateBefore.getTime();
float daysBetween = (difference / (1000*60*60*24));
/* You can also convert the milliseconds to days using this method
* float daysBetween =
* TimeUnit.DAYS.convert(difference, TimeUnit.MILLISECONDS)
*/
System.out.println("Number of Days between dates: "+daysBetween);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Also in Java:
- Title
- java console text color
- Category
- Java
- Title
- how to calculate exponential in java
- Category
- Java
- Title
- get random number from enum in java
- Category
- Java
- Title
- java display message
- Category
- Java
- Title
- java get annotation value
- Category
- Java
- Title
- java map iteration
- Category
- Java
- Title
- add two numbers bitwise
- Category
- Java
- Title
- integer to string java
- Category
- Java
- Title
- java set to list
- Category
- Java
- Title
- java method
- Category
- Java
- Title
- java open file
- Category
- Java
- Title
- java find duplicates in array
- Category
- Java
- Title
- convert int array to integer list java
- Category
- Java
- Title
- get spring application context
- Category
- Java
- Title
- java list to array
- Category
- Java
- Title
- java get location of jar file
- Category
- Java
- Title
- python vs java
- Category
- Java
- Title
- java parse json
- Category
- Java
- Title
- convert array of int to arraylist java
- Category
- Java
- Title
- place.getlatlng() returning null
- Category
- Java
- Title
- snackbar not showing with bottom nav
- Category
- Java
- Title
- regex get string between quotes java
- Category
- Java
- Title
- java self signed certificate truststore
- Category
- Java
- Title
- java list get first element
- Category
- Java
- Title
- java create circle
- Category
- Java
- Title
- could not initialize defaultkotlinsourcesetkt intelij
- Category
- Java
- Title
- e
- Category
- Java
- Title
- java random integer
- Category
- Java
- Title
- how to count an replace substring string in java
- Category
- Java
- Title
- inheritance in java
- Category
- Java
- Title
- java concatenate arrays
- Category
- Java
- Title
- como saber de que tipo es una variable en java
- Category
- Java
- Title
- get today date in java 8
- Category
- Java
- Title
- switch case java
- Category
- Java
- Title
- java return new instance of generic type
- Category
- Java
- Title
- java hashmap example
- Category
- Java
- Title
- how to test how many of one character is in a string java
- Category
- Java
- Title
- how to iterate hashmap java
- Category
- Java
- Title
- break for loop java
- Category
- Java
- Title
- mkyong restful web services spring boot examples post
- Category
- Java
- Title
- sort array java
- Category
- Java
- Title
- programa que convierete un archi de c a java
- Category
- Java
- Title
- how to close a jframe in java with an if statement
- Category
- Java
- Title
- boolean java.lang.String.equals(java.lang.Object)' on a null object reference
- Category
- Java
- Title
- java 8 validate based on pair of strings
- Category
- Java
- Title
- trim() and split() in java
- Category
- Java
- Title
- list java oracle
- Category
- Java
- Title
- java string replace character at position
- Category
- Java
- Title
- faire un timer en java
- Category
- Java
- Title
- java how to make a string lowercase
- Category
- Java
- Title
- java exponencial
- Category
- Java
- Title
- java array to list
- Category
- Java
- Title
- how to get the checkbox checked value in javafx
- Category
- Java
- Title
- string to char in java
- Category
- Java
- Title
- declare array java inline
- Category
- Java
- Title
- loop through array java
- Category
- Java
- Title
- android get distance between two locations kotlin
- Category
- Java
- Title
- remove spaces at beginning and end of string java
- Category
- Java
- Title
- java array check duplicates
- Category
- Java
- Title
- split arraylist items java
- Category
- Java
- Title
- java how to compare strings
- Category
- Java
- Title
- color from hex code flutter
- Category
- Java
- Title
- add video in bootstrap
- Category
- Java
- Title
- string a int java
- Category
- Java
- Title
- how to add a number to an array in java
- Category
- Java
- Title
- how to use for loop for array in java
- Category
- Java
- Title
- java boolean zen
- Category
- Java
- Title
- string replace last character java
- Category
- Java
- Title
- string to long java
- Category
- Java
- Title
- math.pow java
- Category
- Java
- Title
- isnumber java
- Category
- Java
- Title
- java exit
- Category
- Java
- Title
- Java app development
- Category
- Java
- Title
- java initialize int array
- Category
- Java
- Title
- java indexof array
- Category
- Java
- Title
- string remove last character
- Category
- Java
- Title
- in dom parser how to find processing instruction in java
- Category
- Java
- Title
- how to know if String is the same java
- Category
- Java
- Title
- caesar cipher java
- Category
- Java
- Title
- parseints(str) java
- Category
- Java
- Title
- java convert a string to char[]
- Category
- Java
- Title
- read csv in java in spring
- Category
- Java
- Title
- fastapi list query parameter
- Category
- Java
- Title
- java 8 group a collections by 2 property
- Category
- Java
- Title
- java bigdecimal third root
- Category
- Java
- Title
- actionListener java
- Category
- Java
- Title
- android java convert double to 2 decimal places
- Category
- Java
- Title
- sort a map based on keys and values using java 8
- Category
- Java
- Title
- java vs javascript
- Category
- Java
- Title
- loop through java object
- Category
- Java
- Title
- java check if int
- Category
- Java
- Title
- java code to concatinate integer
- Category
- Java
- Title
- hello world in java
- Category
- Java
- Title
- java convert char to int
- Category
- Java
- Title
- blurview android github
- Category
- Java
- Title
- import java.util.*;
- Category
- Java
- Title
- java arraylist to string
- Category
- Java
- Title
- logger in java
- Category
- Java
- Title
- java nextpermutation
- Category
- Java
- Title
- java script using navigator.useragent to detect the browse
- Category
- Java