Javascript Compare datesIn 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 anotherExample: Comparing date with timeExample 1: Comparing different dates with different timings Example2: Comparing same dates with disimilar timings 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. Example2: Comparing two different dates with different timings. Thus, we can compare dates in many possible ways. Changing Date FormatWe can also change or set the format through JavaScript code. The function getFullYear(), GetMonth(), and getDate() allows to set the format of date accordingly. Example1: Changing the date format to 'yyyy-mm-dd'. 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'. Next TopicJavaScript array.length
|