We can compare two dates by using the compareTo( ) method. The compareTo( ) method of the Date class basically returns a positive value when the first date comes after the second date, returns a negative value if the first date comes before the second date, and returns '0' when both dates will be equal.