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
๐ŸŒ
W3Schools
w3schools.com โ€บ js โ€บ js_date_formats.asp
JavaScript Date Formats
If you have a valid date string, you can use the Date.parse() method to convert it to milliseconds.
๐ŸŒ
W3Schools
w3schools.com โ€บ jsref โ€บ jsref_tostring_date.asp
JavaScript Date toString() Method
cssText getPropertyPriority() getPropertyValue() item() length parentRule removeProperty() setProperty() JS Conversion ยท โฎ Previous JavaScript Date Reference Next โฏ ยท Convert a date object to a string: const d = new Date(); let text = d.toString(); Try it Yourself ยป ยท
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());

๐ŸŒ
Esqsoft
esqsoft.com โ€บ javascript_examples โ€บ date-to-epoch
Date/Epoch Time Converter - Javascript tools - Learning examples
JavaScript tool for converting date-to-epoch and/or epoch-to-date. Along with some explanation of the topic and code examples.
๐ŸŒ
W3Schools
w3schools.com โ€บ js โ€บ js_dates.asp
W3Schools.com
February 4, 2026 - When you display a date object in HTML, it is automatically converted to a string, with the toString() method.
๐ŸŒ
W3Schools
w3schools.com โ€บ js โ€บ js_date_reference.asp
JavaScript Date Reference
JS Dates JS Date Formats JS Date Get JS Date Set JS Date Methods JS Temporal New
๐ŸŒ
W3Schools
w3schools.com โ€บ jsref โ€บ jsref_totimestring.asp
JavaScript Date toTimeString() Method
W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ JavaScript โ€บ Reference โ€บ Global_Objects โ€บ Date
Date - JavaScript | MDN - Mozilla
Converts a date to a string following the ISO 8601 Extended Format. ... Returns a string representing the Date using toISOString(). Intended to be implicitly called by JSON.stringify().
Find elsewhere
๐ŸŒ
W3Schools
w3schoolsua.github.io โ€บ js โ€บ js_dates_en.html
JavaScript Date Objects. Lessons for beginners. W3Schools in English
JavaScript Date Objects. Date Output. Creating Date Objects. new Date(). new Date(year, month, ...). Using 6, 4, 3, or 2 Numbers. Previous Century. new Date(dateString). Stores Dates as Milliseconds. new Date(milliseconds). Date Methods. Displaying Dates. Complete JavaScript Date Reference.
๐ŸŒ
Index.dev
index.dev โ€บ blog โ€บ convert-string-to-date-javascript
6 Easy Ways To Convert String to Date in JavaScript
Learn six practical ways to convert strings to dates in JavaScript. Explore techniques like Date Constructor, Moment.js, Regular Expressions, and more, with code examples to improve your date manipulation tasks.
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ convert string to date in javascript
Convert String to Date in JavaScript - Scaler Topics
January 10, 2024 - This article by Scaler Topics will give you a detailed understanding of how to convert string to date in JavaScript with all the programs involved, read to know more.
๐ŸŒ
W3Schools
w3schools.com โ€บ jsref โ€บ jsref_parse.asp
JavaScript Date parse() Method
W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.
๐ŸŒ
TutorialsTeacher
tutorialsteacher.com โ€บ javascript โ€บ javascript-date
JavaScript Date: Create, Convert, Compare Dates in JavaScript
var dt = new Date('2015-02-10T10:12:50.5000z'); </code></pre> <div className="card-footer example-footer"></div></div> </div> <h2>Convert Date Formats</h2> <p> Use different Date methods to convert a date from one format to another format, e.g., to Universal Time, GMT, or local time format.
๐ŸŒ
Turing
turing.com โ€บ kb โ€บ converting-string-to-date-in-js
Learn the Basics of Converting String to Date in JavaScript
As a programmer or web developer, it's important to know the basics of converting a string to date in JavaScript. Find out how to do it in this easy guide.
๐ŸŒ
W3docs
w3docs.com โ€บ javascript
How to Format a JavaScript Date
February 2, 2020 - Read the tutorial and find out the methods and libraries used to format the JavaScript date. Find the method you think is best for you and get the codes.
๐ŸŒ
Epochconvert
epochconvert.com โ€บ programming โ€บ javascript
Date Time Conversion in JavaScript - Epoch Converter
var date = new Date(); var timestamp = Math.floor(date.getTime()/1000.0); We can easily convert unix timestamp to human readable date using date() object