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());

Discussions

JavaScript: how to convert a string to a formatted date?
You can check out the JavaScript Date object. You can create a Date object multiple ways, including passing in the exact string in your question: new Date('1977-04-22');. From there, the Date object has a few built in formatting functions like date.toDateString() which outputs Fri Apr 22 1977. (Be careful though. At the moment, for me it outputs 'Thu Apr 21 1977' since creating the date object with a string defaults to UTC time but the output is in my local timezone). https://css-tricks.com/everything-you-need-to-know-about-date-in-javascript/ and other Google results give more details about how to use the Date object. More on reddit.com
🌐 r/learnprogramming
7
2
May 21, 2020
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
How get a date formatted like 2023-02-07 in JS?
You can do a quick and dirty format to yyyy-mm-dd with date.toISOString().slice(0, 10) More on reddit.com
🌐 r/webdev
26
0
March 13, 2023
How do we work with the date and datetime in JS?
Depending on how the date data is being used, could possibly just store it as a string. That'll bite you if you need to do any kind of math on it though. More on reddit.com
🌐 r/webdev
32
8
December 14, 2021
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › toDateString
Date.prototype.toDateString() - JavaScript - MDN - Mozilla
The toDateString() method of Date instances returns a string representing the date portion of this date interpreted in the local timezone. 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 ...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › toString
Date.prototype.toString() - JavaScript - MDN Web Docs - Mozilla
July 10, 2025 - 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).
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › convert-string-into-date-using-javascript
Convert string into date using JavaScript - GeeksforGeeks
July 11, 2025 - Example: This example formats "May 1, 2019" into a date string, then converts it back to a Date object using Intl.DateTimeFormat() and new Date().
🌐
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.
🌐
freeCodeCamp
freecodecamp.org › news › javascript-string-to-date-date-parsing-in-js
JavaScript String to Date – Date Parsing in JS
June 29, 2022 - We need to be using this format when dealing with dates in JavaScript · 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
Find elsewhere
🌐
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.
🌐
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. parse() returns the time difference in millisec...
🌐
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 - One way to call it is with a dateString argument. The dateString argument needs to be in the ISO 8601 format: ... The string that you want to parse into a Date should match this format or a portion of this 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 » ·...
🌐
Turing
turing.com › kb › converting-string-to-date-in-js
Learn the Basics of Converting String to Date in JavaScript
There are many options for turning a date string into a JavaScript date object. You can do it yourself or pass portions of the date string directly into the Date constructor. Or, to make the task simpler, you can use a third-party library like Moment.js, Date-fns, etc., to achieve your goal.
🌐
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 - Pick a locale and options. They tell how to show the date and time parts. Use format() on a new Intl.DateTimeFormat object. Give it the date string.
🌐
Swovo
swovo.com › blog › convert-string-to-date-javascript
Convert String to Date JavaScript - Swovo
The Date.parse() method in JavaScript converts a date string into a date object’s timestamp. Using a library like Moment.js can provide more flexibility and handle various date formats.
🌐
W3Schools
w3schools.com › js › js_date_formats.asp
JavaScript Date Formats
If you want to modify the time relative to UTC, remove the Z and add +HH:MM or -HH:MM instead: const d = new Date("2015-03-25T12:00:00-06:30"); Try it Yourself » · UTC (Universal Time Coordinated) is the same as GMT (Greenwich Mean Time). Omitting T or Z in a date-time string can give different results in different browsers.
🌐
JavaScript.info
javascript.info › tutorial › the javascript language › data types
Date and time
The string format should be: YYYY-MM-DDTHH:mm:ss.sssZ, where: YYYY-MM-DD – is the date: year-month-day. The character "T" is used as the delimiter. HH:mm:ss.sss – is the time: hours, minutes, seconds and milliseconds.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date
Date - JavaScript | MDN - Mozilla
The following examples show several ways to create JavaScript dates: Note: Creating a date from a string has a lot of behavior inconsistencies. See date time string format for caveats on using different formats. js ·
🌐
W3Schools
w3schools.com › jsref › jsref_todatestring.asp
JavaScript Date toDateString()
cssText getPropertyPriority() ... Date Reference Next ❯ · Get today's date as a readable string: const d = new Date(); let text = d.toDateString(); Try it Yourself » ·...