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: Test it NowComparing date with timeExample 1: Comparing different dates with different timings Test it NowExample2: Comparing same dates with disimilar timings Test it NowComparing 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 NowExample2: Comparing two different dates with different timings. Test it NowThus, 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'. Test it NowWe 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 NowNext TopicJavaScript array.length |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India