Created
November 21, 2016 13:31
-
-
Save santhoshv339/aaaacfbeea6a457c982a505e90bf7dfd to your computer and use it in GitHub Desktop.
Check number of days difference between two dates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.text.ParseException; | |
import java.text.SimpleDateFormat; | |
import java.util.Date; | |
import java.util.concurrent.TimeUnit; | |
public class DateDifferenceCheck { | |
public static void main(String[] args) { | |
SimpleDateFormat myFormat = new SimpleDateFormat("dd MM yyyy"); | |
String inputString1 = "24 05 2016"; | |
String inputString2 = "07 08 2016"; | |
System.out.println(inputString1); | |
System.out.println(inputString2); | |
try { | |
Date date1 = myFormat.parse(inputString1); | |
Date date2 = myFormat.parse(inputString2); | |
long diff = date2.getTime() - date1.getTime(); | |
System.out.println ("Days: " + TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS)); | |
} catch (ParseException e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment