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); // Expected output: 818035920000
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

Javascript Makes Me Cry: Turning a Date into a String
With the exception of the naming of methods, everything you are complaining about is inherited directly from C/POSIX. Have a look at the definition of struct tm from and see if it's familiar. This interface dates back decades, to at least the early 1980s BSD Unix 2.x. More on reddit.com
🌐 r/javascript
87
3
May 29, 2013
Convert Array of Strings to Date without date parsing library
You want to get the dates into YYYY-MM-DD format so that alphanumerical sorting equals chronological sorting. You need to map the months to their numerical representation (and I would change 'August' in your example to 'Aug'), and you need to left-pad your days. Take a look: https://codepen.io/pigparlor/pen/RwVGPwo?editors=0010 More on reddit.com
🌐 r/learnjavascript
7
1
May 23, 2021
🌐
CSS-Tricks
css-tricks.com › how-to-convert-a-date-string-into-a-human-readable-format
How to Convert a Date String into a Human-Readable Format | CSS-Tricks
May 26, 2020 - MDN – https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat
🌐
Reddit
reddit.com › r/javascript › javascript makes me cry: turning a date into a string
r/javascript on Reddit: Javascript Makes Me Cry: Turning a Date into a String
May 29, 2013 - The obvious solution is to have a String class that can do formatting and/or string interpolation, or a Date class that has some sort of equivalent of strftime in addition to the NINE methods it already has that produce one different string format each (toLocaleString, toString, toGMTString, toISOString, toLocaleDateString, toLocaleTimeString, toDateString, toTimeString, toUTCString). I have no intention whatsoever of becoming a "real" Javascript developer if it's at all possible to avoid it, though, but I accept as a fact of life that I have to write some every now and then.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date
Date - JavaScript | MDN
Furthermore, implementations are allowed to support other date formats when the input fails to match this format. The toISOString() method returns a string representation of the date in the date time string format, with the time zone offset always set to Z (UTC).
🌐
Index.dev
index.dev › blog › convert-string-to-date-javascript
6 Simple Methods to Convert Strings to Dates in JavaScript
December 23, 2024 - The match() function yields an array from which we extract the data by destructuring. Ultimately, we instantiate a date object, date4, with the retrieved information. Be aware that the month is zero-indexed in JavaScript, necessitating a subtraction of 1. ... Intl.DateTimeFormat object is an intrinsic component of JavaScript that facilitates the formatting of dates in accordance with local customs. It may also be utilized for parsing translated date strings.
🌐
DEV Community
dev.to › lavary › convert-a-ddmmyyyy-string-to-a-date-object-in-javascript-35o3
Convert a dd/mm/yyyy string to a Date object in JavaScript - DEV Community
February 4, 2023 - JavaScript explicitly supports date strings in ISO 8601 format (YYYY-MM-DDTHH:mm:ss.sssZ). For instance, 2022-12-08, 2022-12-08T09:35:00, etc. However, the behavior of the Date methods with non-standard date formats are implementation-specific ...
Find elsewhere
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › Date
Date() constructor - JavaScript | MDN
If the result is a string, it will be parsed as a date string. Otherwise, the resulting primitive is further coerced to a number and treated as a timestamp. Given at least a year and month, this form of Date() returns a Date object whose component values (year, month, day, hour, minute, second, ...
🌐
Turing
turing.com › kb › converting-string-to-date-in-js
Learn the Basics of Converting String to Date in JavaScript
The given example demonstrates how to use the constructor of the Date class to convert a date from a string to a Date object when the input does not adhere to the ISO standard. There are multiple ways to convert a string value to date in JavaScript using third-party libraries like Moment.js, Date-fns, Day.js, and Temporal.
🌐
W3Schools
w3schools.com › js › js_date_formats.asp
JavaScript Date Formats
Independent of input format, JavaScript will (by default) output dates in full text string format:
🌐
Latenode
community.latenode.com › other questions › javascript
How to parse datetime string into JavaScript Date object - JavaScript - Latenode Official Community
June 20, 2025 - I’m getting a datetime string in this specific format: yyyy-MM-dd HH:mm:ss 2011-07-14 11:23:00 When I try to create a JavaScript Date object from this string, it doesn’t work properly. What’s the right approach to make…
🌐
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 - The string that you want to parse into a Date should match this format or a portion of this format. The “T” character separates the date from the time portion of the string. The “Z” character is the UTC offset representation. UTC is Coordinated Universal Time, which is the primary time standard used to regulate times worldwide.
🌐
TypeScript
typescriptlang.org › docs › handbook › 2 › basic-types.html
TypeScript: Documentation - The Basics
Date());Argument of type 'string' is not assignable to parameter of type 'Date'.2345Argument of type 'string' is not assignable to parameter of type 'Date'.Try · Huh? TypeScript reported an error on our second argument, but why? Perhaps surprisingly, calling Date() in JavaScript returns a string.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › convert-string-into-date-using-javascript
Convert string into date using JavaScript - GeeksforGeeks
July 11, 2025 - Using Intl.DateTimeFormat() and new Date(), the approach formats the input string using specified options for year, month, and day. It then creates a new Date object from the formatted string, effectively converting the string into a date.
🌐
WsCube Tech
wscubetech.com › resources › javascript › programs › string-to-date
Convert String to Date in JavaScript (7 Programs With Output)
January 20, 2026 - Explore 7 simple ways to convert a string to a date in JavaScript. Learn different methods with code examples and output for better understanding.
🌐
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.
🌐
Scaler
scaler.com › home › topics › convert string to date in javascript
Convert String to Date in JavaScript - Scaler Topics
January 10, 2024 - There is a class in JavaScript called the Date class. You can use this function to get the current date and time of the local system. You can also use this class's constructor to convert a date value from string data type to Date data type.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › toDateString
Date.prototype.toDateString() - JavaScript | MDN
const event = new Date(1993, 6, 28, 14, 39, 7); console.log(event.toString()); // Expected output: "Wed Jul 28 1993 14:39:07 GMT+0200 (CEST)" // Note: your timezone may vary console.log(event.toDateString()); // Expected output: "Wed Jul 28 1993" ... A string representing the date portion of ...
🌐
Favtutor
favtutor.com › articles › convert-string-to-date-javascript
Convert String to Date in JavaScript (with code)
November 27, 2023 - Learn how to convert string to date object in Javascript using date constructor and parse method with code.
🌐
Codemia
codemia.io › knowledge-hub › path › parsing_a_string_to_a_date_in_javascript
Parsing a string to a date in JavaScript
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises