I have 2 dates in a String format (ex. 2012-04-23, 2012-03-08), and I want to find the difference between them.
What is the best way to calculate that in Java?
I am just concerned with the date and not the time
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can convert string to date using:
You can read about SimpleDateFormat further here.
As to difference between two dates, you can calculate it in milliseconds with:
getTime()returns the number of milliseconds since January 1, 1970.To convert it in days, use: