Skip to content

Instantly share code, notes, and snippets.

@GiovanniRiefolo
Created February 8, 2023 22:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GiovanniRiefolo/c8ed3e3477e55a31f2d0947531f17130 to your computer and use it in GitHub Desktop.
Save GiovanniRiefolo/c8ed3e3477e55a31f2d0947531f17130 to your computer and use it in GitHub Desktop.
Usage of .toLocaleDateString for Date object format base on locale options
// Get today date value
const today = new Date()
console.log(today) // Wed Feb 08 2023 23:26:49 GMT+0100 (Ora standard dell’Europa centrale)
// Italian date format
const localeIT = "it-IT"
const optionsIT = { weekday:"long", year: "numeric", month: "long", day: "numeric" }
// English / GB date format
const localeGB = "en-GB"
const optionsGB = { weekday:"long", year: "numeric", month: "long", day: "numeric" }
// get italian formatted date
const localDateIT = today.toLocaleDateString(localeIT, optionsIT)
console.log(localDateIT) // "mercoledì 8 febbraio 2023"
// get english / GB formatted date
const localDate = today.toLocaleDateString(localeGB, optionsGB)
console.log(localDateGB) // Wednesday, 8 February 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment