Open PabloRomanH opened 2 years ago
It is possible if you supply a dateformat
<RDatePicker
locale={'de'}
dateFormat={'dd.MM.yyyy'}
/>
but I agree that it should be default behavior
It is possible if you supply a dateformat
<RDatePicker locale={'de'} dateFormat={'dd.MM.yyyy'} />
but I agree that it should be default behavior
That's some bs, but it works this way. I needed it dynamic but whatever, the library is still good enough. What I did to make it work while being dynamic:
import { es, enUS, fr } from 'date-fns/locale';
import { default as ReactDatePicker, registerLocale, setDefaultLocale } from 'react-datepicker';
const DatePicker= ({ locale, ... }) => {
const retardDateFormat = 'MM/dd/yyyy' as const;
const nonRetardDateFormat = 'dd/MM/yyyy' as const;
const locales = {
es: {
locale: es,
format: nonRetardDateFormat,
},
en: {
locale: enUS,
format: retardDateFormat,
},
fr: {
locale: fr,
format: nonRetardDateFormat,
},
};
return (
<ReactDatePicker locale={locale} dateFormat={locales[locale].format} />
)
}
This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 10 days.
Any plans to fix this? Really showing the locale date format is the default when using the JS Date object, so doing this is probably a matter of not formatting the date in a specific format.
Right now the date format that appears in the picker is 'MM/dd/yyyy' instead of the local date format set up in the OS.
Instead, the local date format should be used by default. Right now it's not only not the default, but it's not possible to set it up without installing libraries with big external lists of locales that are prone to errors depending on how each browser and operating system represents the names of the locales.
The local short date format padded with zeros can be easily obtained: