🌐
Futurestud.io
futurestud.io › tutorials › how-to-format-a-date-yyyy-mm-dd-in-javascript-or-node-js
How to Format a Date YYYY-MM-DD in JavaScript or Node.js
January 5, 2023 - In case you’re wondering about the provided getDay method in JavaScript: it returns the day of the week and not the day of the month. That’s why we’re using getDate. Here’s a sample format(date) function formatting the given date in YYYY-MM-DD: /** * Returns the `date` formatted in YYYY-MM-DD. * * @param {Date} date * * @returns {String} */ function format (date) { if (!(date instanceof Date)) { throw new Error('Invalid "date" argument.
🌐
W3Schools
w3schools.com › js › js_date_formats.asp
JavaScript Date Formats
Independent of input format, JavaScript will (by default) output dates in full text string format: ISO 8601 is the international standard for the representation of dates and times.
Discussions

How do I format a date in JavaScript? - Stack Overflow
If you’re looking how to parse a string to a Date object, see Parsing a string to a date in JavaScript. ... If you need slightly less control over formatting than the currently accepted answer, Date#toLocaleDateString can be used to create standard locale-specific renderings. More on stackoverflow.com
🌐 stackoverflow.com
visualforce - Date Format to String Format in JavaScript Remoting - Salesforce Stack Exchange
Moment will format all your dates any way you want them, compare them properly (js won't with some ugly hacks!!) and do things like time zone adjustments to undo what Salesforce does via locale. ... I did not test it, but it sounds a good solution. I faced the same problem before, what I did is to return String in my remote action and not date. ... To convert a JavaScript ... More on salesforce.stackexchange.com
🌐 salesforce.stackexchange.com
November 14, 2014
How get a date formatted like 2023-02-07 in JS?
You can do a quick and dirty format to yyyy-mm-dd with date.toISOString().slice(0, 10) More on reddit.com
🌐 r/webdev
26
0
March 13, 2023
How can I convert a JavaScript Date object into a custom string format?
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 formatting I need. Could someone guide me on how to accomplish this conversion ... More on community.latenode.com
🌐 community.latenode.com
0
January 27, 2025
text-based open standard designed for human-readable data interchange
whitespace
object
combox respuesta json
JSON (JavaScript Object Notation, pronounced /ˈdʒeɪsən/ or /ˈdʒeɪˌsɒn/) is an open standard file format and data interchange format that uses human-readable text to store and transmit data objects consisting of name–value pairs … Wikipedia
Factsheet
JavaScript Object Notation
Filename extension .json
Internet media type application/json
Factsheet
JavaScript Object Notation
Filename extension .json
Internet media type application/json
🌐
JSON
json.org
JSON
JSON is a text format that is completely language independent but uses conventions that are familiar to programmers of the C-family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others.
Top answer
1 of 16
3084

If you need slightly less control over formatting than the currently accepted answer, Date#toLocaleDateString can be used to create standard locale-specific renderings. The locale and options arguments let applications specify the language whose formatting conventions should be used, and allow some customization of the rendering.

Options key examples:

  1. day:
    The representation of the day.
    Possible values are "numeric", "2-digit".
  2. weekday:
    The representation of the weekday.
    Possible values are "narrow", "short", "long".
  3. year:
    The representation of the year.
    Possible values are "numeric", "2-digit".
  4. month:
    The representation of the month.
    Possible values are "numeric", "2-digit", "narrow", "short", "long".
  5. hour:
    The representation of the hour.
    Possible values are "numeric", "2-digit".
  6. minute: The representation of the minute.
    Possible values are "numeric", "2-digit".
  7. second:
    The representation of the second.
    Possible values are "numeric", 2-digit".
  8. hour12:
    The representation of time format.
    Accepts boolean true or false

All these keys are optional. You can change the number of options values based on your requirements, and this will also reflect the presence of each date time term.

Note: If you would only like to configure the content options, but still use the current locale, passing null for the first parameter will cause an error. Use undefined instead.

For different languages:

  1. "en-US": For American English
  2. "en-GB": For British English
  3. "hi-IN": For Hindi
  4. "ja-JP": For Japanese

You can use more language options.

For example

var options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };
var today  = new Date();

console.log(today.toLocaleDateString("en-US")); // 9/17/2016
console.log(today.toLocaleDateString("en-US", options)); // Saturday, September 17, 2016
console.log(today.toLocaleDateString("hi-IN", options)); // शनिवार, 17 सितंबर 2016

You can also use the toLocaleString() method for the same purpose. The only difference is this function provides the time when you don't pass any options.

// Example
9/17/2016, 1:21:34 PM

References:

  • toLocaleString()

  • toLocaleDateString()

2 of 16
1756

For custom-delimited date formats, you have to pull out the date (or time) components from a DateTimeFormat object (which is part of the ECMAScript Internationalization API), and then manually create a string with the delimiters you want.

To do this, you can use DateTimeFormat#formatToParts. You could destructure the array, but that is not ideal, as the array output depends on the locale:

{ // example 1
   let formatter = new Intl.DateTimeFormat('en');
   let example = formatter.formatToParts();
   console.log(example);
}
{ // example 2
   let formatter = new Intl.DateTimeFormat('hi');
   let example = formatter.formatToParts();
   console.log(example);
}

Better would be to map a format array to resultant strings:

function join(date, options, separator) {
   function format(option) {
      let formatter = new Intl.DateTimeFormat('en', option);
      return formatter.format(date);
   }
   return options.map(format).join(separator);
}

let options = [{day: 'numeric'}, {month: 'short'}, {year: 'numeric'}];
let joined = join(new Date, options, '-');
console.log(joined);

You can also pull out the parts of a DateTimeFormat one-by-one using DateTimeFormat#format, but note that when using this method, as of March 2020, there is a bug in the ECMAScript implementation when it comes to leading zeros on minutes and seconds (this bug is circumvented by the approach above).

let date = new Date(2010, 7, 5);
let year = new Intl.DateTimeFormat('en', { year: 'numeric' }).format(date);
let month = new Intl.DateTimeFormat('en', { month: 'short' }).format(date);
let day = new Intl.DateTimeFormat('en', { day: '2-digit' }).format(date);
console.log(`{month}-${year}`);

When working with dates and times, it is usually worth using a library (eg. luxon, date-fns, moment.js is not recommended for new projects) because of the many hidden complexities of the field.

Note that the ECMAScript Internationalization API, used in the solutions above is not supported in IE10 (0.03% global browser market share in Feb 2020).

🌐
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_tostring_date.asp
JavaScript Date toString() Method
The toString() method returns a date object as a string. Every JavaScript object has a toString() method.
🌐
Turing
turing.com › kb › converting-string-to-date-in-js
Learn the Basics of Converting String to Date in JavaScript
JavaScript has a constructor called the Date constructor. This function can be used to retrieve the local system's current date and time. Additionally, you can change a date value from a string data type to a Date data type with the constructor. Let's take a quick look at this element. ... A string containing a date in the ISO 8601 calendar date extended format should be provided as the first argument to the constructor of the Date class.
Find elsewhere
🌐
Reddit
reddit.com › r/webdev › how get a date formatted like 2023-02-07 in js?
r/webdev on Reddit: How get a date formatted like 2023-02-07 in JS?
March 13, 2023 -

I'm going insane. I had this feature working perfectly. Took 2 weeks vacation. I come back and it's broken.

I know y'all will say this is impossible, but I was getting that format by using `date.toLocaleDateString('en-CA')`. I know the spec says that format is "dd/MM/yyyy", which isn't what I want, but I was giving me the format in the title, I swear to God.

This is such a stupid little thing but I've already spent hours on SO. It's just endless threads about people confused about datetimes and the differences between timezones and offsets and no one's talking about this silly little thing.

I have my new date: Wed Feb 08 2023 00:00:00 GMT-0500 (Eastern Standard Time)

I just need a simple operation to flip the string around so it becomes 2023-03-08

That is it. Please help

p.s. the date is always set to midnight user local time so offset can be ignored. Whatever day they're experiencing is the day to be formatted. Thank you

🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-validate-string-date-format-in-javascript
How to Validate String Date Format in JavaScript ? - GeeksforGeeks
July 23, 2025 - Moment.js is a javascript library which is used to validate the Date. It has a function "moment" which can two aruments and it returns true if the date argument matches to the formate arument else it will return false. ... Example: This describes how to validate string date format using moment library in JavaScript.
🌐
CSS-Tricks
css-tricks.com › how-to-convert-a-date-string-into-a-human-readable-format
How to Convert a Date String into a Human-Readable Format | CSS-Tricks
May 26, 2020 - I’ll be the first to admit that I’m writing this article, in part, because it’s something I look up often and want to be able to find it next time. Formatting a date string that you get from an API in JavaScript can take many shapes — anything from loading all of Moment.js to have very ...
🌐
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…
🌐
Chris Pietschmann
pietschsoft.com › post › 2023 › 09 › 28 › javascript-parse-string-to-a-date
JavaScript: Parse a String to a Date | Chris Pietschmann
September 28, 2023 - Then, you can parse the date string using Moment.js and specify the desired time zone: var st = "2023-09-28T14:30:00"; var dt_st = moment(st).utc(); // Parse as UTC · Moment.js offers a wide range of formatting and manipulation options, making it a powerful tool for working with dates and times in JavaScript.
🌐
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?

🌐
date-fns
date-fns.org › docs › Getting-Started
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.
🌐
freeCodeCamp
freecodecamp.org › news › javascript-string-to-date-date-parsing-in-js
JavaScript String to Date – Date Parsing in JS
June 29, 2022 - Dates are a pretty fundamental concept. We use them all the time. And computers use them all the time. But parsing dates using JavaScript can be a little...well, interesting. In this article, we'll: Discuss date formatting Turn a wee ol' string into...
🌐
Google AI
ai.google.dev › gemini api › structured outputs
Structured outputs | Gemini API | Google AI for Developers
January 12, 2026 - curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-3.1-pro-preview:generateContent" \ -H "x-goog-api-key: $GEMINI_API_KEY" \ -H 'Content-Type: application/json' \ -X POST \ -d '{ "contents": [{ "parts": [{"text": "Search for all details for the latest Euro."}] }], "tools": [ {"googleSearch": {}}, {"urlContext": {}} ], "generationConfig": { "responseMimeType": "application/json", "responseJsonSchema": { "type": "object", "properties": { "winner": {"type": "string", "description": "The name of the winner."}, "final_match_score": {"type": "string", "description": "The final scor
🌐
Strava
developers.strava.com › docs › reference
Strava Developers
var StravaApiV3 = require('strava_api_v3'); var defaultClient = StravaApiV3.ApiClient.instance; // Configure OAuth2 access token for authorization: strava_oauth var strava_oauth = defaultClient.authentications['strava_oauth']; strava_oauth.accessToken = "YOUR ACCESS TOKEN" var api = new StravaApiV3.ActivitiesApi() var name = name_example; // {String} The name of the activity. var sportType = sportType_example; // {String} Sport type of activity. For example - Run, MountainBikeRide, Ride, etc. var startDateLocal = 2013-10-20T19:20:30+01:00; // {Date} ISO 8601 formatted date time.
🌐
TutorialsPoint
tutorialspoint.com › how-to-convert-date-to-string-in-typescript
How to Convert Date to String in TypeScript?
The date object after converting to string using the toString() method: Wed Dec 14 2022 10:45:11 GMT+0000 (UTC) The date object after converting to string using the toISOString() method: 2022-12-14T10:45:11.874Z · The approach to creating the ...