Altered piece of code I often use:
Date.prototype.yyyymmdd = function() {
var mm = this.getMonth() + 1; // getMonth() is zero-based
var dd = this.getDate();
return [this.getFullYear(),
(mm>9 ? '' : '0') + mm,
(dd>9 ? '' : '0') + dd
].join('');
};
var date = new Date();
date.yyyymmdd();
Answer from o-o on Stack OverflowW3Schools
w3schools.com › jsref › jsref_tostring_date.asp
JavaScript Date toString() Method
cssText getPropertyPriority() ... Date Reference Next ❯ · Convert a date object to a string: const d = new Date(); let text = d.toString(); Try it Yourself » ·...
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › toString
Date.prototype.toString() - JavaScript | MDN
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).
Videos
02:14
How to convert a date string to a JavaScript date object - YouTube
How to Convert a Datetime String to a Date String in JavaScript
16:02
Format Your Own Dates With JavaScript - YouTube
00:30
JavaScript How To Convert Date To String - YouTube
JavaScript Training Tutorial Converting the Date to a String
Converting String to Date in JavaScript
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).
W3Schools
w3schools.com › js › js_date_formats.asp
JavaScript Date Formats
JS Examples JS HTML DOM JS HTML Input JS HTML Objects JS HTML Events JS Browser JS Editor JS Exercises JS Quiz JS Website JS Syllabus JS Study Plan JS Interview Prep JS Bootcamp JS Certificate JS Reference ... The ISO format follows a strict standard in JavaScript. The other formats are not so well defined and might be browser specific. Independent of input format, JavaScript will (by default) output dates in full text string format:
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.
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date
Date - JavaScript | MDN
There are many ways to format a date as a string. The JavaScript specification only specifies one format to be universally supported: the date time string format, a simplification of the ISO 8601 calendar date extended format.
W3Schools
w3schools.com › jsref › jsref_todatestring.asp
JavaScript Date toDateString()
cssText getPropertyPriority() getPropertyValue() item() length parentRule removeProperty() setProperty() JS Conversion ... The toDateString() method returns the date (not the time) of a date object as a string.
Top answer 1 of 16
717
Altered piece of code I often use:
Date.prototype.yyyymmdd = function() {
var mm = this.getMonth() + 1; // getMonth() is zero-based
var dd = this.getDate();
return [this.getFullYear(),
(mm>9 ? '' : '0') + mm,
(dd>9 ? '' : '0') + dd
].join('');
};
var date = new Date();
date.yyyymmdd();
2 of 16
399
I didn't like adding to the prototype. An alternative would be:
const rightNow = new Date();
const res = rightNow.toISOString().slice(0,10).replace(/-/g,"");
// Next line is for code snippet output only
document.body.innerHTML += res;
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › toTimeString
Date.prototype.toTimeString() - JavaScript | MDN
const event = new Date("August 19, 1975 23:15:30"); console.log(event.toTimeString()); // Expected output: "23:15:30 GMT+0200 (CEST)" // Note: your timezone may vary ... A string representing the time portion of the given date (see description for the format).
W3Schools
w3schools.com › jsref › jsref_parse.asp
JavaScript Date parse() Method
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...
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().
Scaler
scaler.com › home › topics › convert string to date in javascript
Convert String to Date in JavaScript - Scaler Topics
January 10, 2024 - The Date class also provides us with another way to convert a date from string to Date format. The Date class has a static method called parse. You can use this method in the same way that you would use the Date class's constructor.
Top answer 1 of 6
9
There is a free (and awesome) library for Javascript called Datejs that gives you all sorts of formatting and parsing capabilities (see the FormatSpecifiers documentation).
2 of 6
6
There isn’t anything built into JavaScript that allows you to format the display of a date like strftime does.
The closest is Date().toLocaleString(), which returns the date as a string formatted according to the local time zone.
Day.js
day.js.org › docs › en › parse › string-format
String + Format · Day.js
You may specify a boolean for the last argument to use strict parsing. Strict parsing requires that the format and input match exactly, including delimiters. dayjs('1970-00-00', 'YYYY-MM-DD').isValid() // true dayjs('1970-00-00', 'YYYY-MM-DD', true).isValid() // false dayjs('1970-00-00', 'YYYY-MM-DD', 'es', true).isValid() // false · If you don't know the exact format of an input string, but know it could be one of many, you can use an array of formats.