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
🌐
Node.js
nodejs.org › api › fs.html
File system | Node.js v25.8.0 Documentation
If the path refers to a file path that is not a symbolic link, the file is deleted. See the POSIX unlink(2) documentation for more detail. ... Returns: <Promise> Fulfills with undefined upon success. Change the file system timestamps of the object referenced by path. ... Values can be either numbers representing Unix epoch time, Dates, or a numeric string like '123456789.0'.
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 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
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
Convert Array of Strings to Date without date parsing library
You want to get the dates into YYYY-MM-DD format so that alphanumerical sorting equals chronological sorting. You need to map the months to their numerical representation (and I would change 'August' in your example to 'Aug'), and you need to left-pad your days. Take a look: https://codepen.io/pigparlor/pen/RwVGPwo?editors=0010 More on reddit.com
🌐 r/learnjavascript
7
1
May 21, 2021
🌐
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.
🌐
W3Schools
w3schools.com › jsref › jsref_tostring_date.asp
JavaScript Date toString() Method
The toString() method returns a date object as a string. Every JavaScript object has a toString() method.
🌐
React Datepicker
reactdatepicker.com
React Datepicker crafted by HackerOne
A simple and reusable datepicker component for React.
🌐
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).
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › toDateString
Date.prototype.toDateString() - JavaScript | MDN
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
🌐
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 ...
🌐
Reddit
reddit.com › r/javascript › javascript makes me cry: turning a date into a string
r/javascript on Reddit: Javascript Makes Me Cry: Turning a Date into a String
May 29, 2013 - The obvious solution is to have a String class that can do formatting and/or string interpolation, or a Date class that has some sort of equivalent of strftime in addition to the NINE methods it already has that produce one different string format each (toLocaleString, toString, toGMTString, toISOString, toLocaleDateString, toLocaleTimeString, toDateString, toTimeString, toUTCString). I have no intention whatsoever of becoming a "real" Javascript developer if it's at all possible to avoid it, though, but I accept as a fact of life that I have to write some every now and then.
🌐
HTML Standard
html.spec.whatwg.org
HTML Standard
Furthermore, due to the JavaScript memory model, there are situations which not only are un-representable via serialized script execution, but also un-representable via serialized statement execution among those scripts.
🌐
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?

🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-program-to-convert-date-to-string
JavaScript Program to Convert Date to String - GeeksforGeeks
July 23, 2025 - JavaScript date.toString() method is used to convert the given Date object’s contents into a string.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date
Date - JavaScript | MDN
December 8, 2025 - Date.parse() and the Date() constructor both accept strings in the date time string format as input. Furthermore, implementations are allowed to support other date formats when the input fails to match this format.
🌐
W3Schools
w3schools.com › js › js_date_methods.asp
JavaScript Date Methods
The getDay() method returns the weekday of a date as a number (0-6). In JavaScript, the first day of the week (day 0) is Sunday. Some countries in the world consider the first day of the week to be Monday.
🌐
Mongoose
mongoosejs.com › docs › guide.html
Mongoose v9.2.4: Schemas
Each schema maps to a MongoDB collection and defines the shape of the documents within that collection. import mongoose from 'mongoose'; const { Schema } = mongoose; const blogSchema = new Schema({ title: String, // String is shorthand for {type: String} author: String, body: String, comments: [{ body: String, date: Date }], date: { type: Date, default: Date.now }, hidden: Boolean, meta: { votes: Number, favs: Number } });
🌐
Nuxt UI
ui.nuxt.com › docs › components › table
Vue Table Component - Nuxt UI
You can add a new column that renders a Checkbox component inside the header and cell to select rows using the TanStack Table Row Selection APIs. ... <script setup lang="ts"> import { h, resolveComponent } from 'vue' import type { TableColumn } from '@nuxt/ui' const UCheckbox = resolveComponent('UCheckbox') const UBadge = resolveComponent('UBadge') type Payment = { id: string date: string status: 'paid' | 'failed' | 'refunded' email: string amount: number } const data = ref<Payment[]>([ { id: '4600', date: '2024-03-11T15:30:00', status: 'paid', email: 'james.anderson@example.com', amount: 594
🌐
Home Assistant
home-assistant.io › docs › configuration › templating
Templating - Home Assistant
If the input is a datetime.date object, midnight is added as the time. This function can also be used as a filter. as_timestamp(value, default) converts a datetime object or string to UNIX timestamp.
🌐
Flagging Down
flaggingdown.com › p › the-dylan-petty-rehearsal-tapes
The Bob Dylan-Tom Petty Rehearsal Tapes - by Ray Padgett
1 week ago - 46 tracks worth, from some indeterminate place and date near the end of 1985 as they prepared to head to Australia. Because this particular tape originated on a bootleg label, it is not the raw tape. That would likely be hours long, much of it devoted to false starts or dead air or studio chatter or a guitarist tuning their E string interminably.
🌐
Semantic Versioning
semver.org
Semantic Versioning 2.0.0 | Semantic Versioning
And one with numbered capture groups instead (so cg1 = major, cg2 = minor, cg3 = patch, cg4 = prerelease and cg5 = buildmetadata) that is compatible with ECMA Script (JavaScript), PCRE (Perl Compatible Regular Expressions, i.e. Perl, PHP and R), Python and Go. ... ^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$ The Semantic Versioning specification was originally authored by Tom Preston-Werner, inventor of Gravatar and cofounder of GitHub.