The best string format for string parsing is the date ISO format together with the JavaScript Date object constructor.

Examples of ISO format: YYYY-MM-DD or YYYY-MM-DDTHH:MM:SS.

But wait! Just using the "ISO format" doesn't work reliably by itself. String are sometimes parsed as UTC and sometimes as localtime (based on browser vendor and version). The best practice should always be to store dates as UTC and make computations as UTC.

To parse a date as UTC, append a Z - e.g.: new Date('2011-04-11T10:20:30Z').

To display a date in UTC, use .toUTCString(),
to display a date in user's local time, use .toString().

More info on MDN | Date and this answer.

For old Internet Explorer compatibility (IE versions less than 9 do not support ISO format in Date constructor), you should split datetime string representation to it's parts and then you can use constructor using datetime parts, e.g.: new Date('2011', '04' - 1, '11', '11', '51', '00'). Note that the number of the month must be 1 less.


Alternate method - use an appropriate library:

You can also take advantage of the library Moment.js that allows parsing date with the specified time zone.

Answer from Pavel Hodek on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › parse
Date.parse() - JavaScript | MDN
// Standard date-time string format const unixTimeZero = Date.parse("1970-01-01T00:00:00Z"); // Non-standard format resembling toUTCString() const javaScriptRelease = Date.parse("04 Dec 1995 00:12:00 GMT"); console.log(unixTimeZero); // Expected output: 0 console.log(javaScriptRelease); // ...
🌐
W3Schools
w3schools.com › jsref › jsref_parse.asp
JavaScript Date parse() Method
// Calculate milliseconds in a year const minute = 1000 * 60; const hour = minute * 60; const day = hour * 24; const year = day * 365; // Compute years const d = Date.parse("March 21, 2012"); let years = Math.round(d / year); Try it Yourself ...
Top answer
1 of 16
1087

The best string format for string parsing is the date ISO format together with the JavaScript Date object constructor.

Examples of ISO format: YYYY-MM-DD or YYYY-MM-DDTHH:MM:SS.

But wait! Just using the "ISO format" doesn't work reliably by itself. String are sometimes parsed as UTC and sometimes as localtime (based on browser vendor and version). The best practice should always be to store dates as UTC and make computations as UTC.

To parse a date as UTC, append a Z - e.g.: new Date('2011-04-11T10:20:30Z').

To display a date in UTC, use .toUTCString(),
to display a date in user's local time, use .toString().

More info on MDN | Date and this answer.

For old Internet Explorer compatibility (IE versions less than 9 do not support ISO format in Date constructor), you should split datetime string representation to it's parts and then you can use constructor using datetime parts, e.g.: new Date('2011', '04' - 1, '11', '11', '51', '00'). Note that the number of the month must be 1 less.


Alternate method - use an appropriate library:

You can also take advantage of the library Moment.js that allows parsing date with the specified time zone.

2 of 16
452

Unfortunately I found out that

var mydate = new Date('2014-04-03');
console.log(mydate.toDateString());

returns "Wed Apr 02 2014". I know it sounds crazy, but it happens for some users.

The bulletproof solution is the following:

var parts ='2014-04-03'.split('-');
// Please pay attention to the month (parts[1]); JavaScript counts months from 0:
// January - 0, February - 1, etc.
var mydate = new Date(parts[0], parts[1] - 1, parts[2]); 
console.log(mydate.toDateString());

🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date
Date - JavaScript | MDN
... Returns the numeric value ... 00:00:00 UTC, with leap seconds ignored. ... Parses a string representation of a date and returns the number of milliseconds since January 1, 1970 00:00:00 UTC, with leap seconds ignored....
🌐
JavaScript.info
javascript.info › tutorial › the javascript language › data types
Date and time
The call to Date.parse(str) parses the string in the given format and returns the timestamp (number of milliseconds from 1 Jan 1970 UTC+0). If the format is invalid, returns NaN. ... Date and time in JavaScript are represented with the Date object.
🌐
TutorialsPoint
tutorialspoint.com › home › javascript › javascript date parsing
JavaScript Date.parse() Method
September 1, 2008 - Following is the syntax of JavaScript Date parse() method − ... The dateString will be the date string that we want to parse. It can be in different formats, such as "YYYY-MM-DD" or "YYYY-MM-DDTHH:mm:ss", and it can include time zone information.
🌐
freeCodeCamp
freecodecamp.org › news › javascript-string-to-date-date-parsing-in-js
JavaScript String to Date – Date Parsing in JS
June 29, 2022 - Date.parse() tells us the number of milliseconds that have elapsed since January 1, 1970. This is helpful when comparing multiple dates.
🌐
Tabnine
tabnine.com › home › how to use date.parse in javascript
How to Use Date.parse in JavaScript - Tabnine
July 25, 2024 - The Date.parse() method takes as an argument a string representing a date, and returns the number of milliseconds that have elapsed between January 1, 1970, 00:00:00 UTC and the date provided.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › javascript-date-parse-method
JavaScript Date parse() Method | GeeksforGeeks
July 12, 2024 - The code takes a date string "February 18, 2018, 12:30 PM" and parses it using the Date.parse() method, which returns the number of milliseconds since January 1, 1970.
🌐
Reality Ripple
udn.realityripple.com › docs › Web › JavaScript › Reference › Global_Objects › Date › parse
Date.parse() - JavaScript
For example, "2011-10-10" (date-only form), "2011-10-10T14:48:00" (date-time form), or "2011-10-10T14:48:00.000+09:00" (date-time form with milliseconds and time zone) can be passed and will be parsed.
🌐
Chris Pietschmann
pietschsoft.com › post › 2023 › 09 › 28 › javascript-parse-string-to-a-date
JavaScript: Parse a String to a Date | Chris Pietschmann
September 28, 2023 - Let’s say you have the following variables: var st = "2023-09-28T14:30:00"; var dt = new Date(); You want to parse the st string into a Date object dt_st such that dt_st holds the same date and time as st.
🌐
Byby
byby.dev › js-format-date
How to parse and format a date in JavaScript
This is often necessary when working with dates that are obtained from external sources such as APIs or user input fields. JavaScript provides several methods for parsing dates, such as Date.parse() and new Date() constructor. It’s important to note that the date string must be in a specific format that can be recognized by the parsing method.
🌐
CoreUI
coreui.io › answers › how-to-parse-a-date-string-in-javascript
How to parse a date string in JavaScript · CoreUI
October 24, 2025 - const dateString = '2023-12-25T10:30:00Z' const parsedDate = new Date(dateString)
🌐
EDUCBA
educba.com › home › software development › software development tutorials › javascript tutorial › javascript date parse
JavaScript Date parse | Learn How does Date Parsing work in JavaScript?
June 30, 2023 - Given string value 1 January 2019 to date.parse() method. It converts the string to date. But as discussed in the important note, the resultant date is always in milliseconds. So, we get an output of 154628100000.
Address   Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
Javatpoint
javatpoint.com › javascript-date-parse-method
JavaScript date parse() method - javatpoint
JavaScript date parse() method with javascript tutorial, introduction, javascript oops, application of javascript, loop, variable, objects, map, typedarray etc.
🌐
Sentry
sentry.io › sentry answers › javascript › parsing a string to a `date` in javascript
Parsing a string to a `Date` in JavaScript | Sentry
If you can, use the full date and time in your date string. To parse a date string as UTC, append a “Z” to the end of the date:
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › Date
Date() constructor - JavaScript | MDN
When one parameter is passed to the Date() constructor, Date instances are specially treated. All other values are converted to primitives. If the result is a string, it will be parsed as a date string.
🌐
DEV Community
dev.to › astorm › javascript-date-string-parsing-3c8d
Javascript Date String Parsing - DEV Community
April 29, 2021 - Let's see how it handles abbreviated ISO date strings. > moment= require('moment') //... > moment('2021-04-01') Moment<2021-04-01T00:00:00-07:00> Success! Unlike the native Date object, moment doesn't assume a UTC timezone.
🌐
Index.dev
index.dev › blog › convert-string-to-date-javascript
6 Easy Ways To Convert String to Date in JavaScript
This example employs a regular expression to identify and extract the year, month, and day from the text. The match() function yields an array from which we extract the data by destructuring.
🌐
date-fns
date-fns.org › v1.28.5 › docs › parse
date-fns - modern JavaScript date utility library
If an argument is a string, the function tries to parse it. Function accepts complete ISO 8601 formats as well as partial implementations.