In the previous section, we discussed the date methods as well as the constructors.
Here, with the help of those methods, we will learn to compare dates.
Basically, there are different ways by which we can compare dates, such as:
Comparing two dates with one another
Example:Test it Now
Comparing date with time
Example 1: Comparing different dates with different timingsTest it Now
Example2: Comparing same dates with disimilar timingsTest it Now
Comparing date with getTime()
A better approach to make comparison between dates is to use getTime() function. This function lets converting date into numeric value to directly compare them.
Example1: Comparing current date and time with a given date and time.Test it Now
Example2: Comparing two different dates with different timings.Test it Now
Thus, we can compare dates in many possible ways.
Changing Date Format
Example1: Changing the date format to 'yyyy-mm-dd'.Test it Now
We can also set the date and time format according to our need.
Example2: Changing the datetime format to 'yyyy-dd-mm hh:mm:ss'.Test it Now