Created
February 8, 2023 22:56
-
-
Save GiovanniRiefolo/c8ed3e3477e55a31f2d0947531f17130 to your computer and use it in GitHub Desktop.
Usage of .toLocaleDateString for Date object format base on locale options
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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