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
The Date.parse() static method parses a string representation of a date, and returns the date's timestamp.
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());

🌐
W3Schools
w3schools.com › jsref › jsref_parse.asp
JavaScript Date parse() Method
❮ Previous JavaScript Date Reference Next ❯ · let ms = Date.parse("March 21, 2012"); Try it Yourself » · parse() parses a date string and returns the time difference since January 1, 1970. parse() returns the time difference in milliseconds.
🌐
Zipy
zipy.ai › blog › parsing-a-string-to-a-date-in-javascript
parsing a string to a date in javascript
April 12, 2024 - The most straightforward way to convert a string to a date in JavaScript is using the Date.parse() method. This function takes a date string as an argument and returns the number of milliseconds since January 1, 1970, 00:00:00 UTC.
🌐
freeCodeCamp
freecodecamp.org › news › javascript-string-to-date-date-parsing-in-js
JavaScript String to Date – Date Parsing in JS
June 29, 2022 - Here's what this format looks like. You're familiar with it already – it just combines a date and time into one big piece of info that JavaScript can get cozy with. // YYYY-MM-DDTHH:mm:ss.sssZ // A date string in ISO 8601 Date Format
🌐
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 - The most reliable way to parse a date string in JavaScript is to use the ISO date format. ISO format can be in the form of YYYY-MM-DD or YYYY-MM-DDTHH:MM:SS. However, there’s a caveat: JavaScript may interpret the input string as either UTC ...
🌐
Index.dev
index.dev › blog › convert-string-to-date-javascript
6 Easy Ways To Convert String to Date in JavaScript
An alternative approach to turn a string into a date is by · using the Date.parse() function.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-date-parse-method
JavaScript Date parse() Method - GeeksforGeeks
July 11, 2025 - The JavaScript Date parse() method parses a date string and returns the number of milliseconds between the date string and midnight of January 1, 1970, UTC.
Find elsewhere
🌐
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) Here the ISO format string '2023-12-25T10:30:00Z' is passed to the Date constructor, which parses it into a proper Date object.
🌐
Day.js
day.js.org › docs › en › parse › string-format
String + Format · Day.js
Strict parsing requires that the format and input match exactly, including delimiters. dayjs('1970-00-00', 'YYYY-MM-DD').isValid() // true dayjs('1970-00-00', 'YYYY-MM-DD', true).isValid() // false dayjs('1970-00-00', 'YYYY-MM-DD', 'es', true).isValid() // false · If you don't know the exact format of an input string, but know it could be one of many, you can use an array of formats.
🌐
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 - 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....
🌐
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.
🌐
TutorialsPoint
tutorialspoint.com › home › javascript › javascript date parsing
JavaScript Date.parse() Method
September 1, 2008 - The Date.parse() method in JavaScript is a static method which is used to parse a string representation of a date and time and convert it into the number of milliseconds since January 1, 1970, 00:00:00 UTC (also known as the Unix Epoch).
🌐
Scaler
scaler.com › home › topics › convert string to date in javascript
Convert String to Date in JavaScript - Scaler Topics
January 10, 2024 - You can pass the date in string format, and the function will return the date in the form of number which represents the number of milliseconds since January 1, 1970, 00:00:00 UTC.
🌐
DEV Community
dev.to › onlinemsr › how-to-convert-string-to-date-in-javascript-p39
How to Convert String to Date in JavaScript - DEV Community
April 6, 2024 - It’s easy with the Date.parse() method! Just give it a date string that follows the rules, and it will give you back a magic number. This number is how many milliseconds have passed since the start of 1970 in UTC.
🌐
DEV Community
dev.to › astorm › javascript-date-string-parsing-3c8d
Javascript Date String Parsing - DEV Community
April 29, 2021 - In javascript, you can use the Date.parse method to automatically parse a date string and get a unix timestamp back, or you can pass a string directly to the Date object's constructor function.
🌐
JavaScript.info
javascript.info › tutorial › the javascript language › data types
Date and time
A single letter Z would mean UTC+0. ... or even YYYY. 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)....