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 › jsref › jsref_parse.asp
W3Schools.com
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...
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 › parse
Date.parse() - JavaScript | MDN
The Date.parse() static method parses a string representation of a date, and returns the date's timestamp.
🌐
Sequelize
sequelize.org
Sequelize
Sequelize is a modern TypeScript and Node.js ORM for Oracle, Postgres, MySQL, MariaDB, SQLite and SQL Server, and more. Featuring solid transaction support, relations, eager and lazy loading, read replication and more. ... import { Sequelize, DataTypes } from 'sequelize'; const sequelize = new Sequelize('sqlite::memory:'); const User = sequelize.define('User', { username: DataTypes.STRING, birthday: DataTypes.DATE, });
🌐
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.
🌐
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
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › toString
Date.prototype.toString() - JavaScript | MDN
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).
Find elsewhere
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › toDateString
Date.prototype.toDateString() - JavaScript | MDN
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 ...
🌐
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.
🌐
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().
🌐
Zod
zod.dev › api
Defining schemas | Zod
The z.iso.date() method validates strings in the format YYYY-MM-DD.
🌐
TypeScript
typescriptlang.org › docs › handbook › 2 › basic-types.html
TypeScript: Documentation - The Basics
What we did was add type annotations on person and date to describe what types of values greet can be called with. You can read that signature as ”greet takes a person of type string, and a date of type Date“.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date
Date - JavaScript | MDN
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 ·
🌐
Express.js
expressjs.com › en › guide › routing.html
Express routing
Create a router file named birds.js in the app directory, with the following content: const express = require('express') const router = express.Router() // middleware that is specific to this router const timeLog = (req, res, next) => { console.log('Time: ', Date.now()) next() } router.use(timeLog) // define the home page route router.get('/', (req, res) => { res.send('Birds home page') }) // define the about route router.get('/about', (req, res) => { res.send('About birds') }) module.exports = router
🌐
Open Graph
ogp.me
The Open Graph protocol
The metadata is identical to video.movie. These are globally defined objects that just don't fit into a vertical but yet are broadly used and agreed upon. ... payment:expires_at - datetime - The date and time including minutes and seconds on which the payment link expires. payment:status - enum(PENDING, PAID, FAILED, EXPIRED) - Status of the payment. payment:id - string - The unique identifier associated with the payment link for a given payment gateway or service provider.
🌐
Starship
starship.rs › config
Starship: Cross-Shell Prompt
Starship is the minimal, blazing fast, and extremely customizable prompt for any shell! Shows the information you need, while staying sleek and minimal. Quick installation available for Bash, Fish, ZSH, Ion, Tcsh, Elvish, Nu, Xonsh, Cmd, and Powershell.
🌐
Latenode
community.latenode.com › other questions › javascript closures
How can I convert a JavaScript Date object into a custom string format? - JavaScript Closures - Latenode Official Community
January 27, 2025 - I’m looking for a way to transform a JavaScript Date object into a specific string format, such as ‘DD-MMM-YYYY’ (for example, 10-Aug-2010). I’ve encountered several approaches, but none have produced the exact formattin…
🌐
Bun
bun.com
Bun — A fast all-in-one JavaScript runtime
Use individual tools like bun test or bun install in Node.js projects, or adopt the complete stack with a fast JavaScript runtime, bundler, test runner, and package manager built in. Bun aims for 100% Node.js compatibility. ... Queries per second. 100 rows x 100 parallel queries ... Use them together as an all-in-one toolkit, or adopt them incrementally.
🌐
Oracle
forums.oracle.com › ords › apexds › post › convert-string-to-date-in-javascript-0266
Convert string to date in javascript
July 29, 2013 - Hi,On my apex page I have a hidden item P1_STORE_DT which stores date in '01-AUG-13' format.Now what i need to do is convert this into date in javascriptOn page load i execute below codevar d=new Date...