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 Web Docs
July 10, 2025 - 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());

Discussions

[AskJS] Are there any JS libraries that will parse a date string and return a format string?
because almost everyone is more interested in just being able to parse the strings, not in getting out what format they were in Because it is not possible. What format is 09/09/09 01-01-01? Something could be done if you have multiple data entries with the same format, but even then if you are unlucky you wouldn't be able to determine it for sure. More on reddit.com
🌐 r/javascript
28
12
October 12, 2021
new Date() works in Chrome but throws 'Invalid date' in Firefox

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date

Note: Parsing of date strings with the Date constructor (and Date.parse(), which works the same way) is strongly discouraged due to browser differences and inconsistencies.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse

my guess is that chrome accepts a space in the date but firefox does not.

new Date('2020-10-19 07:57:52+00:00')

works for me

More on reddit.com
🌐 r/firefox
35
81
July 30, 2019
Why is C++ so terrible when it comes to date/time manipulation?
snort ... Did somebody call? :-) More on reddit.com
🌐 r/cpp
153
260
January 22, 2021
DateTime representation.
We use MongoDB and Apollo Server Express in TaskTrain.app . Here's the the TypeScript code from our DateTime custom scalar type resolver using the native JavaScript Date object, which seems to play well across MongoDB, Node.JS, Apollo Server Express, and our Apollo Angular Client: private dateTimeCustomScalarTypeResolve(): GraphQLScalarType { return new GraphQLScalarType({ name: 'DateTime', description: 'Timestamp custom scalar type', parseValue(variableFromClient: Date | number | string): Date | string { switch (typeof variableFromClient) { case 'number': return new Date(variableFromClient); case 'string': return variableFromClient !== '' ? new Date(variableFromClient) : ''; case 'object': return variableFromClient instanceof Date ? variableFromClient : undefined; default: return undefined; } }, parseLiteral(parameterFromClient: ValueNode): Date | string { switch (parameterFromClient.kind) { case Kind.INT: return new Date(parameterFromClient.value); case Kind.STRING: return parameterFromClient.value.length ? new Date(parameterFromClient.value) : ''; default: return undefined; } }, serialize(valueToClient: Date | string | number): Date { return (typeof valueToClient === 'string' || typeof valueToClient === 'number' || valueToClient instanceof Date) ? new Date(valueToClient) : null; // Apollo automatically serializes to ISO DateTime string } }); } More on reddit.com
🌐 r/graphql
10
4
June 26, 2019
🌐
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.
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.
🌐
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.
🌐
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.
🌐
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
February 18, 2014 - 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).
🌐
Sentry
sentry.io › sentry answers › javascript › parsing a string to a `date` in javascript
Parsing a string to a `Date` in JavaScript | Sentry
February 15, 2023 - 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 - Mozilla
... 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....
🌐
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.
🌐
Bobby Hadz
bobbyhadz.com › blog › javascript-convert-string-to-date-object
How to convert a String to a Date object in JavaScript | bobbyhadz
September 1, 2008 - Use the `Date()` constructor to convert a string to a `Date` object in JavaScript.
🌐
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.