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
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
There are many ways to format a date as a string. The JavaScript specification only specifies one format to be universally supported: the date time string format, a simplification of the ISO 8601 calendar date extended format.
🌐
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 · js ·
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › toString
Date.prototype.toString() - JavaScript | MDN
const event = new Date("August 19, 1975 23:15:30"); console.log(event.toString()); // Expected output: "Tue Aug 19 1975 23:15:30 GMT+0200 (CEST)" // Note: your timezone may vary ... A string representing the given date (see description for the format).
🌐
W3Schools
w3schools.com › jsref › jsref_tostring_date.asp
JavaScript Date toString() Method
cssText getPropertyPriority() ... Date Reference Next ❯ · Convert a date object to a string: const d = new Date(); let text = d.toString(); Try it Yourself » ·...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › Date
Date() constructor - JavaScript | MDN
The returned date's timestamp is the same as the number returned by Date.now(). ... An integer value representing the timestamp (the number of milliseconds since midnight at the beginning of January 1, 1970, UTC — a.k.a. the epoch). ... A string value representing a date, parsed and interpreted using the same algorithm implemented by Date.parse().
Find elsewhere
🌐
Index.dev
index.dev › blog › convert-string-to-date-javascript
6 Easy Ways To Convert String to Date in JavaScript
This blog post outlines six straightforward methods for converting a string to a date in JavaScript. Every approach possesses distinct advantages and applications: Date Constructor: Efficient and direct for ISO format. Date.parse(): Suitable for timestamps including temporal data. Moment.js: Optimal for intricate date operations.
🌐
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 ...
🌐
Sentry
sentry.io › sentry answers › javascript › parsing a string to a `date` in javascript
Parsing a string to a `Date` in JavaScript | Sentry
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.
🌐
W3Schools
w3schools.com › js › js_date_formats.asp
JavaScript Date Formats
JS Examples JS HTML DOM JS HTML Input JS HTML Objects JS HTML Events JS Browser JS Editor JS Exercises JS Quiz JS Website JS Syllabus JS Study Plan JS Interview Prep JS Bootcamp JS Certificate JS Reference ... The ISO format follows a strict standard in JavaScript. The other formats are not so well defined and might be browser specific. Independent of input format, JavaScript will (by default) output dates in full text string format:
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › convert-string-into-date-using-javascript
Convert string into date using JavaScript - GeeksforGeeks
July 11, 2025 - The JavaScript Date parse() Method is used to know the exact number of milliseconds that have passed since midnight, January 1, 1970, till the date we provide. ... Example: In this example, we will use date.parse() method to get time out of ...
🌐
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.
🌐
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
🌐
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.
🌐
TutorialsTeacher
tutorialsteacher.com › javascript › javascript-date
JavaScript Date: Create, Convert, Compare Dates in JavaScript
The following example converts a date string to DD-MM-YYYY format. ... var date = new Date('4-1-2015'); // M-D-YYYY var d = date.getDate(); var m = date.getMonth() + 1; var y = date.getFullYear(); var dateString = (d &lt;= 9 ? '0' + d : d) + '-' + (m <= 9 ? '0' + m : m) + '-' + y; ... Use third party JavaScript Date library like datejs.com or momentjs.com to work with Dates extensively in JavaScript.
🌐
W3Schools
w3schools.com › jsref › jsref_parse.asp
JavaScript Date parse() Method
cssText getPropertyPriority() ... Date.parse("March 21, 2012"); Try it Yourself » · parse() parses a date string and returns the time difference since January 1, 1970....