๐ŸŒ
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
Discussions

javascript - How to convert "YYYY-MM-DD" format to Date object - Stack Overflow
You can do new Date('2022-02-17'). ... Sign up to request clarification or add additional context in comments. ... To answer the question in the title, you can simply just initialize a Date object by using the string you have ... Now formatting it into something else can be a tedious to do. Using library such as date-fns would be easier. Javascript ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Parsing a string to a date in JavaScript - Stack Overflow
New site design and philosophy for Stack Overflow: Starting February 24, 2026... Iโ€™m Jody, the Chief Product and Technology Officer at Stack Overflow. Letโ€™s... 223 How to create a date object from string in javascript More on stackoverflow.com
๐ŸŒ stackoverflow.com
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 to create a date object from a string treating the string as local time?
JavaScript Date objects leave something to be desired. For parsing strings like that, you could append the time and timezone to the string for parsing purposes. For example, if I wanted to create today's date in CDT (GMT-5) I could do this: let date = new Date("2022-09-07 00:00:00-05:00"); By appending 00:00:00 I'm specifying a time, and the -05:00 is the timezone. Alternatively, you could create the object with the constructor that accepts year, month, and day: let date2 = new Date(2022, 8, 7) You might notice something odd there, I used 8 for the month instead of 9. That's just how JS handles months (and day of week), as a zero-based number instead of one-based. As to parsing a date string without a specified timezone? I think it will always parse that as UTC. More on reddit.com
๐ŸŒ r/learnprogramming
4
1
September 7, 2022
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ JavaScript โ€บ Reference โ€บ Global_Objects โ€บ Date โ€บ Date
Date() constructor - JavaScript | MDN
The Date() constructor creates Date objects. When called as a function, it returns a string representing the current time. const date1 = new Date("December 17, 1995 03:24:00"); // Sun Dec 17 1995 03:24:00 GMT... const date2 = new Date("1995-12-17T03:24:00"); // Sun Dec 17 1995 03:24:00 GMT...
๐ŸŒ
W3Schools
w3schools.com โ€บ js โ€บ js_dates.asp
JavaScript Dates
February 4, 2026 - new Date() creates a date object with the current date and time: ... Date string formats are described in the next chapter.
๐ŸŒ
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 ยท const today = new Date(); const birthday = new Date("December 17, 1995 03:24:00"); // DISCOURAGED: may not work in all runtimes const birthday2 = new Date("1995-12-17T03:24:00"); // This is standardized and will work reliably const birthday3 = new Date(1995, 11, 17); // the month is 0-indexed const birthday4 = new Date(1995, 11, 17, 3, 24, 0); const birthday5 = new Date(628021800000); // passing epoch timestamp ยท
๐ŸŒ
DEV Community
dev.to โ€บ lavary โ€บ convert-a-ddmmyyyy-string-to-a-date-object-in-javascript-35o3
Convert a dd/mm/yyyy string to a Date object in JavaScript - DEV Community
February 4, 2023 - That said, if your date string is ISO-8601-compliant, you can safely pass it to the Date() constructor: const dateObj = new Date('2022-12-08') console.log(dateObj) // output: Thu Dec 08 2022 00:00:00 GMT+0000 (Western European Standard Time)
๐ŸŒ
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 - Call the Date() constructor with the new operator to create a Date object. The Date() constructor can be called with a variable number of arguments and different types of arguments.
Find elsewhere
๐ŸŒ
Turing
turing.com โ€บ kb โ€บ converting-string-to-date-in-js
Learn the Basics of Converting String to Date in JavaScript
A four-digit year (at least), possibly with zeros padding the left. // create a date variable const date = new Date(2022, 6, 20, 14, 28, 7); // the time will be neglected console.log(date.toDateString());
๐ŸŒ
Index.dev
index.dev โ€บ blog โ€บ convert-string-to-date-javascript
6 Simple Methods to Convert Strings to Dates in JavaScript
The match() function yields an array from which we extract the data by destructuring. Ultimately, we instantiate a date object, date4, with the retrieved information. Be aware that the month is zero-indexed in JavaScript, necessitating a subtraction of 1. ... Intl.DateTimeFormat object is an intrinsic component of JavaScript that facilitates the formatting of dates in accordance with local customs. It may also be utilized for parsing translated date strings. const date5 = new Date(Intl.DateTimeFormat('en-US').format(new Date('2024-10-09'))); console.log(date5); // Output: Wed Oct 09 2024 ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ javascript โ€บ convert-string-into-date-using-javascript
Convert string into date using JavaScript - GeeksforGeeks
July 11, 2025 - Using Intl.DateTimeFormat() and new Date(), the approach formats the input string using specified options for year, month, and day. It then creates a new Date object from the formatted string, effectively converting the string into a date.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ javascript โ€บ how-to-convert-a-date-string-to-timestamp-in-javascript
How to Convert a Date String to Timestamp in JavaScript ? - GeeksforGeeks
July 23, 2025 - ... Example: In this example, we are using the above-explained method. ... In this approach, using new Date() creates a date object from a string, then .getTime() extracts the Unix timestamp (milliseconds since 1970).
๐ŸŒ
JavaScript.info
javascript.info โ€บ tutorial โ€บ the javascript language โ€บ data types
Date and time
We can always create a date from a timestamp using new Date(timestamp) and convert the existing Date object to a timestamp using the date.getTime() method (see below). Dates before 01.01.1970 have negative timestamps, e.g.: // 31 Dec 1969 let ...
๐ŸŒ
date-fns
date-fns.org
date-fns - modern JavaScript date utility library
date-fns provides the most comprehensive yet simple and consistent toolset for manipulating JavaScript dates in a browser & Node.js.
๐ŸŒ
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 ...
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());

๐ŸŒ
W3Schools
w3schools.com โ€บ js โ€บ js_date_formats.asp
JavaScript Date Formats
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. When setting a date, without specifying the time zone, JavaScript will use the browser's time zone.
๐ŸŒ
Squash
squash.io โ€บ how-to-parse-a-string-to-a-date-in-javascript
How to Parse a String to a Date in JavaScript
We then create a new Date object by passing the milliseconds value to the Date constructor. Using the Date.parse() method allows for more flexibility in terms of the input date string format.
๐ŸŒ
SPGuides
spguides.com โ€บ convert-string-to-date-in-typescript
How to Convert String to Date in TypeScript?
February 6, 2024 - However, the string should be in a format recognized by the Date.parse method, such as YYYY-MM-DD or YYYY-MM-DDTHH:MM:SS. const dateString = '2024-01-31T09:45:00'; const dateObject = new Date(dateString);
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ how-to-format-a-date-with-javascript-date-formatting-in-js
How to Format a Date with JavaScript โ€“ Date Formatting in JS
November 7, 2024 - Before we dive into date formatting, let's get familiar with the JavaScript Date object. It provides methods to work with dates and times effectively. To create a new date instance, you can use the new Date() constructor.