How to find number of days between two given dates in Java?



Problem description :


Write a program in Java that prints number of days between two given dates.

Concept :


We are using below method of Date class that is present in java.util.* package.

public long getTime() -> This method returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this Date object. Then we have to convert Milliseconds to Days. I hope everyone is aware of below conversions. Using this we can easily convert Milliseconds to Days.

1 Day = 24 Hours
1 Hour = 60 Minutes
1 Minute = 60 Seconds
1 Second =1000 Milliseconds


Recommended :



Java Program :




Output :


Output of Java program that prints number of days between two given dates.
Output - How to find number of days between two given dates in Java?

Note : You can also use this calculator for validating your result.

References :



Thank you friends, I hope you have clearly understood the solution of this problem. If you have any doubt, suggestion or query please feel free to comment below. You can also discuss this solution in our forum.

Tags : Date and Time Problems, Days between two dates in Java, Solution in Java, String, DateFormat, SimpleDateFormat, Regular expressions.

About Author:

I am simple guy with lot of ambitions. My main motive is to share whatever knowledge I have related to programming. With me you can easily learn how to solve any programming problem in Java.You can connect with me on social networking sites also.


Let's Get Connected: Linkedin | Facebook |

How to find number of days between two given dates in Java? How to find number of days between two given dates in Java? Reviewed by Rohit Agarwal on 12/09/2016 Rating: 5

No comments:

Please provide your valuable comments. If you have any suggestion please share with me I will work on it and if you have any question or doubt please ask, don't hesitate. I am your friend, i will clarify all your doubts.

Powered by Blogger.