I use the esm version of date-fns and you can use the same type of formats that moment uses :

import { format } from 'date-fns/esm'
import { enUS, fr } from 'date-fns/esm/locale'

I'll store the locales in an object :

this.dateLocales = { fr: fr, en: enUS }

and use these formats :

LT: 'h:mm aa',
LTS: 'h:mm:ss aa',
L: 'MM/DD/YYYY',
LL: 'MMMM D YYYY',
LLL: 'MMMM D YYYY h:mm aa',
LLLL: 'dddd, MMMM D YYYY h:mm aa'

So you can do :

format(
  new Date(2014, 6, 2),
  'LL',
  {locale: this.dateLocales.fr}
)

Those formats are localised

Answer from Lakston on Stack Overflow
🌐
GitHub
github.com › orgs › date-fns › discussions › 2724
List of all locales and corresponding languages? · date-fns · Discussion #2724
Documentation could be better https://github.com/date-fns/date-fns/tree/main/src/locale · Beta Was this translation helpful? Give feedback. ... There was an error while loading. Please reload this page. Something went wrong. There was an error while loading. Please reload this page. ... in .net maui 2022 visualstudio its possible to get the locales using the TextToSpeech even if you dont plan to use it beyond this ability to get all country names and codes.....
Discussions

Date-fns format and locale problem
Hi, I used the sample from Material UI and tried to modify it. I am having a bit of trouble trying to do locale on a Material UI datepicker with a custom format but I am not sure what I am doing wrong… Below is the link to my code so far: More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
1
0
May 25, 2021
javascript - Failing to "dynamically" import date-fns/locale libs - TypeScript giving an attempted import error - Stack Overflow
I want to use date-fns library for handling date formatting but I have to import the whole date-fns/locale as I can't know beforehand which locale will be needed: import * as dateFnsLocales from 'date-fns/locale'; The problem is, some of the locales are in different code format (for example, support for deutsch language is enabled ... More on stackoverflow.com
🌐 stackoverflow.com
Default locale
I am getting an error like this ... module 'date-fns/locale/en'. ... Beta Was this translation helpful? Give feedback. ... There was an error while loading. Please reload this page. Something went wrong. There was an error while loading. Please reload this page. ... It seems that the 'en' locale is not available. However, you can use one of the ... More on github.com
🌐 github.com
1
1
September 13, 2022
date-fns: How to format dates for multiple languages?
I want to display the date in a way that makes sense to users of any of these three languages, and right now I do it like this: import en from 'date-fns/locale/en'; import fr from 'date-fns/locale/fr'; import es from 'date-fns/locale/es'; import { format } from 'date-fns'; ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
MUI X
mui.com › x › react-date-pickers › adapters-locale
Date and Time Pickers - Date format and localization - MUI X
enen-gbzh-cnde · Date · 04/17/2022 · Date · Time · 06:30 PM · Time · For date-fns, import the locale and pass it to LocalizationProvider: We support date-fns package v2.x, v3.x, and v4.x major versions.
🌐
date-fns
date-fns.org › docs › Locale
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.
🌐
GitHub
github.com › date-fns › date-fns › blob › main › docs › i18n.md
date-fns/docs/i18n.md at main · date-fns/date-fns
// app/_lib/format.js import { format } from "date-fns"; import { enGB, eo, ru } from "date-fns/locale"; const locales = { enGB, eo, ru }; // by providing a default string of 'PP' or any of its variants for `formatStr` // it will format dates in whichever way is appropriate to the locale export default function (date, formatStr = "PP") { return format(date, formatStr, { locale: locales[window.__localeId__], // or global.__localeId__ }); } // Later: import format from "app/_lib/format"; window.__localeId__ = "enGB"; format(friday13, "EEEE d"); //=> 'Friday 13' window.__localeId__ = "eo"; format(friday13, "EEEE d"); //=> 'vendredo 13' // If the format string is omitted, it will take the default for the locale.
Author   date-fns
Find elsewhere
🌐
GitHub
github.com › orgs › date-fns › discussions › 3679
Default locale · date-fns · Discussion #3679
September 13, 2022 - I am getting an error like this for 'en' - Unable to resolve the path to module 'date-fns/locale/en'. ... Beta Was this translation helpful? Give feedback. ... There was an error while loading. Please reload this page. Something went wrong. There was an error while loading. Please reload this page. ... It seems that the 'en' locale is not available. However, you can use one of the following specific English locales:
🌐
npm
npmjs.com › package › date-fns
date-fns - npm
September 17, 2024 - Immutable & Pure: Built using pure functions and always returns a new date instance. TypeScript: The library is 100% TypeScript with brand-new handcrafted types. I18n: Dozens of locales. Include only what you need. ... import { compareAsc, format } from "date-fns"; format(new Date(2014, 1, 11), "yyyy-MM-dd"); //=> '2014-02-11' const dates = [ new Date(1995, 6, 2), new Date(1987, 1, 11), new Date(1989, 6, 10), ]; dates.sort(compareAsc); //=> [ // Wed Feb 11 1987 00:00:00, // Mon Jul 10 1989 00:00:00, // Sun Jul 02 1995 00:00:00 // ]
      » npm install date-fns
    
Published   Sep 17, 2024
Version   4.1.0
🌐
GitHub
github.com › date-fns › date-fns › blob › main › docs › i18nContributionGuide.md
date-fns/docs/i18nContributionGuide.md at main · date-fns/date-fns
Put this function in _lib/formatRelative/index.js inside your locale directory. Relative date formats written in format token string format. See the list of tokens: https://date-fns.org/docs/format. Has to process lastWeek, yesterday, today, tomorrow, nextWeek and other tokens. // In `en-US` locale var formatRelativeLocale = { lastWeek: "'last' eeee 'at' p", yesterday: "'yesterday at' p", today: "'today at' p", tomorrow: "'tomorrow at' p", nextWeek: "eeee 'at' p", other: "P", }; export default function formatRelative(token, date, baseDate, options) { return formatRelativeLocale[token]; }
Author   date-fns
🌐
Stack Overflow
stackoverflow.com › questions › 76017714 › date-fns-how-to-format-dates-for-multiple-languages
date-fns: How to format dates for multiple languages?
I want to display the date in a way that makes sense to users of any of these three languages, and right now I do it like this: import en from 'date-fns/locale/en'; import fr from 'date-fns/locale/fr'; import es from 'date-fns/locale/es'; import ...
🌐
GitHub
github.com › palantir › blueprint › issues › 6481
datetime2/DatePicker3 component - "Could not load "en-US" date-fns locale" in Vite · Issue #6481 · palantir/blueprint
July 27, 2023 - The DatePicker3 works as expected but the console show an error: dateFnsLocaleUtils.ts:35 [Blueprint] Could not load "en-US" date-fns locale, please check that this locale code is supported: https://github.com/date-fns/date-fns/tree/main/src/locale · And the locale en-US exists.
Author   EduBic
🌐
GitHub
github.com › date-fns › date-fns › tree › main › src › locale › en-US
date-fns/src/locale/en-US at main · date-fns/date-fns
⏳ Modern JavaScript date utility library ⌛️. Contribute to date-fns/date-fns development by creating an account on GitHub.
Author   date-fns
🌐
GitHub
github.com › date-fns › date-fns › issues › 1898
how can I update date-fns default locale inside tests? · Issue #1898 · date-fns/date-fns
August 16, 2020 - I am trying to move from moment.js to date-fns and some tests are using moment.locale(locale) to change the locale from one test to another.
Author   bboydflo
🌐
DigitalOcean
digitalocean.com › community › tutorials › js-date-fns
Quick Tour of date-fns, a Simple JavaScript Date Library | DigitalOcean
1 week ago - const format = require('date-fns/format'); const addYears = require('date-fns/addYears'); const stPattysDay = new Date('2020/03/17'); const stPattysDayNextYear = addYears(stPattysDay, 1); const formattedDate = format(stPattysDayNextYear, 'MMMM dd, yyyy'); console.log(formattedDate); // => "March 17, 2021" Formatting is pretty easy, but what about locales? We know that users will be visiting your website from around the world, and we don’t want to assume they speak our native language.
🌐
GitHub
github.com › mui › mui-x › issues › 11470
[pickers] Problems after update to date-fns 3.0.1 · Issue #11470 · mui/mui-x
January 29, 2020 - ./mypath/date-picker.tsx:30:31 Type error: Property 'enUS' is missing in type 'Locale' but required in type 'typeof import("/Users/MyName/myProject/node_modules/date-fns/locale/en-US")'. 28 | 29 | return ( > 30 | <LocalizationProvider adapterLocale={de} dateAdapter={AdapterDateFns}> | ^ 31 ...
Author   Tockra