JavaScript date parse Method | Examples code

JavaScript Date parse() method parses a date string and returns the number of milliseconds since January 1, 1970, 00:00:00 UTC. But if the given string date is unrecognized or, in some cases, contains illegal date values then it will return NaN (Not-a-Number).


Parameter Values

A string representing a date.

Example of JavaScript date parse

Let’s see simple example, where will try to get the the number of milliseconds between January 1, 1970 and July 21, 2020:


Example of JavaScript date parse

How to Javascript convert date format

You should look into momentjs, which is a javascript date/time library. By using this Library, you can easily convert between dates of different formats. In your case, it would be:

string newDate = moment(currentDate, currentFormatString).format(newFormatString)

For example, moment("21/10/14", "DD/MM/YY").format("MM/DD/YY") would return "10/21/14"

Q: What is the common Error javascript date parse method?

Answer: If the input string of date is not correct, it returns NaN (not a number). See below example of it:-

Output: NaN

Do comment if you have any doubts and suggestions on this topic.

Note: The All JS Examples codes are tested on the Safari browser (Version 12.0.2) and Chrome.
OS: macOS 10.14 Mojave
Code: HTML 5 Version

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.