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 - // 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: 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
How can I turn my date-time string into a JS Date object to be used in my template?
Try this: new Date({{ value|date:"U" }}) date:"U" should get the Unix timestamp . You might have to multiply that value by 1000 to get the correct format, e.g. new Date({{ value|date:"U" }} * 1000) More on reddit.com
🌐 r/django
4
3
January 14, 2017
How to combine a date object with a time string and convert to UTC?
eg: var date = new Date(); var time = '13:31:59'; var timeSplit = time.split(':'); date.setHours(timeSplit[0]); date.setMinutes(timeSplit[1]); date.setSeconds(timeSplit[2]); var utcDateTime = [date.getUTCFullYear(), date.getUTCMonth() + 1, date.getUTCDate()].join('-') + ' ' + [date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds()].join(':') + 'Z'; // eg "2020-5-24 11:31:59Z" using vanilla js date: https://www.w3schools.com/jsref/jsref_obj_date.asp this takes the local date/ time and convert it into UTC dateTime or use a wrapper libray such as moment or date-fns More on reddit.com
🌐 r/vuejs
4
3
March 28, 2020
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
🌐
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
There are five different ways to change a date value from a string data type to a date type. By using the Date() function in JavaScript. By using parse(), UTC() which are static methods of the Date construct.
🌐
Index.dev
index.dev › blog › convert-string-to-date-javascript
6 Easy Ways To Convert String to Date in JavaScript
date in JavaScript, accompanied with distinct code samples and practical insights. A straightforward technique to convert a string to a date is by use the Date constructor.
🌐
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.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › toDateString
Date.prototype.toDateString() - JavaScript - MDN Web Docs
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 the given date (see description for the 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 - 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.
🌐
W3Schools
w3schools.com › jsref › jsref_parse.asp
JavaScript Date parse() Method
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING INTRO TO HTML & CSS BASH RUST
🌐
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 - Did you know you can turn a string into a date in JavaScript? 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.
🌐
Reddit
reddit.com › r/learnprogramming › javascript: how to convert a string to a formatted date?
r/learnprogramming on Reddit: JavaScript: how to convert a string to a formatted date?
May 21, 2020 -

This has got me stumped. I've read dozens of StackOverflow posts about similar things but I cannot get it working.

I have a string like 1977-04-22. I want to change this to a different kind of date format, eg 22nd April 1977.

I am really not sure how to go about this and am very confused.

Would anyone be able to help me or point me in the right direction?

🌐
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 - Then, you can parse the date string using Moment.js and specify the desired time zone: var st = "2023-09-28T14:30:00"; var dt_st = moment(st).utc(); // Parse as UTC · Moment.js offers a wide range of formatting and manipulation options, making it a powerful tool for working with dates and times in JavaScript.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › toString
Date.prototype.toString() - JavaScript | MDN - 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).
🌐
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 › js › js_date_formats.asp
JavaScript Date Formats
Independent of input format, JavaScript will (by default) output dates in full text string format: ISO 8601 is the international standard for the representation of dates and times. The ISO 8601 syntax (YYYY-MM-DD) is also the preferred JavaScript date format: const d = new Date("2015-03-25"); Try it Yourself » · The computed date will be relative to your time zone.
🌐
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
❮ Previous JavaScript Date Reference Next ❯ · Convert a date object to a string: const d = new Date(); let text = d.toString(); Try it Yourself » · The toString() method returns a date object as a string.
🌐
Medium
medium.com › @onlinemsr › how-to-convert-string-to-date-in-javascript-db7fac68ede7
How to Convert String to Date in JavaScript | by Raja MSR | Medium
April 3, 2024 - Did you know you can turn a string into a date in JavaScript? 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.
🌐
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.