[Feature Request] Date Picker support for dd/mm/yyyy and yyyy/mm/dd
Is your feature request related to a problem? Please describe.
In most countries we don't use the American date format
Describe the solution you'd like
As an international user, I would expect to able to configure the date picker to be set using the dd/mm/yyyy or the yyyy/mm/dd
Describe alternatives you've considered
Screenshots or Videos
No response
@Armandotrsg can you check if wrapping the component with I18nProvider and the locale set for what you need solves your issue? I'm currently using:
import { I18nProvider } from "@react-aria/i18n";
import { DateInput } from "@nextui-org/react";
<I18nProvider locale="en-GB">
<DateInput ... />
</I18nProvider>
And this allows me to use the configuration dd/mm/yyyy.
@Armandotrsg can you check if wrapping the component with I18nProvider and the locale set for what you need solves your issue? I'm currently using:
import { I18nProvider } from "@react-aria/i18n"; import { DateInput } from "@nextui-org/react"; <I18nProvider locale="en-GB"> <DateInput ... /> </I18nProvider>And this allows me to use the configuration dd/mm/yyyy.
it didn't work for me, could you show a screenshot of it working with the dd/mm/yyyy format?
@Armandotrsg can you check if wrapping the component with I18nProvider and the locale set for what you need solves your issue? I'm currently using:
import { I18nProvider } from "@react-aria/i18n"; import { DateInput } from "@nextui-org/react"; <I18nProvider locale="en-GB"> <DateInput ... /> </I18nProvider>And this allows me to use the configuration dd/mm/yyyy.
it didn't work for me, could you show a screenshot of it working with the dd/mm/yyyy format?
Thanks! It worked for me, it even allows to use it in Spanish as well:
<I18nProvider locale="es-GB">
<DateRangePicker
value={date}
onChange={setDate}
label="Fecha de postulación"
description="dd/mm/yyyy"
labelPlacement="outside"
/>
</I18nProvider>
Hey guys you can set up this globally using the NextUIProvider locale property https://nextui.org/docs/api-references/nextui-provider#locale
Supported locales:
const localeValues = [
'fr-FR', 'fr-CA', 'de-DE', 'en-US', 'en-GB', 'ja-JP',
'da-DK', 'nl-NL', 'fi-FI', 'it-IT', 'nb-NO', 'es-ES', 'sv-SE', 'pt-BR',
'zh-CN', 'zh-TW', 'ko-KR', 'bg-BG', 'hr-HR', 'cs-CZ', 'et-EE', 'hu-HU',
'lv-LV', 'lt-LT', 'pl-PL', 'ro-RO', 'ru-RU', 'sr-SP', 'sk-SK', 'sl-SI', 'tr-TR', 'uk-UA',
'ar-AE', 'ar-DZ', 'AR-EG', 'ar-SA', 'el-GR', 'he-IL', 'fa-AF', 'am-ET', 'hi-IN', 'th-TH'
];
const calendars = [
'gregory', 'japanese', 'buddhist', 'roc', 'persian', 'indian',
'islamic-umalqura', 'islamic-civil', 'islamic-tbla', 'hebrew',
'coptic', 'ethiopic', 'ethioaa'
]
So for Spanish, you could do the following:
"use client";
import {type ReactNode} from "react";
import {NextUIProvider} from "@nextui-org/react";
export function AppProvider(props: AppProviderProps) {
const {children, className} = props;
return (
<NextUIProvider locale="es-ES" className={className}>
{children}
</NextUIProvider>
);
}
interface AppProviderProps {
children: ReactNode;
className?: string;
}
@Armandotrsg can you check if wrapping the component with I18nProvider and the locale set for what you need solves your issue? I'm currently using:
import { I18nProvider } from "@react-aria/i18n"; import { DateInput } from "@nextui-org/react"; <I18nProvider locale="en-GB"> <DateInput ... /> </I18nProvider>And this allows me to use the configuration dd/mm/yyyy.
it didn't work for me, could you show a screenshot of it working with the dd/mm/yyyy format?
Thanks! It worked for me, it even allows to use it in Spanish as well:
<I18nProvider locale="es-GB"> <DateRangePicker value={date} onChange={setDate} label="Fecha de postulación" description="dd/mm/yyyy" labelPlacement="outside" /> </I18nProvider>
This dosnt work for me, i want to be able to get formatt the Input like this mm/yyyy
how do i get only month and year, i need to formatt it like this mm/yyyy, there should be a dateFormat props
Hey guys you can set up this globally using the
NextUIProviderlocaleproperty https://nextui.org/docs/api-references/nextui-provider#localeSupported locales:
const localeValues = [ 'fr-FR', 'fr-CA', 'de-DE', 'en-US', 'en-GB', 'ja-JP', 'da-DK', 'nl-NL', 'fi-FI', 'it-IT', 'nb-NO', 'es-ES', 'sv-SE', 'pt-BR', 'zh-CN', 'zh-TW', 'ko-KR', 'bg-BG', 'hr-HR', 'cs-CZ', 'et-EE', 'hu-HU', 'lv-LV', 'lt-LT', 'pl-PL', 'ro-RO', 'ru-RU', 'sr-SP', 'sk-SK', 'sl-SI', 'tr-TR', 'uk-UA', 'ar-AE', 'ar-DZ', 'AR-EG', 'ar-SA', 'el-GR', 'he-IL', 'fa-AF', 'am-ET', 'hi-IN', 'th-TH' ]; const calendars = [ 'gregory', 'japanese', 'buddhist', 'roc', 'persian', 'indian', 'islamic-umalqura', 'islamic-civil', 'islamic-tbla', 'hebrew', 'coptic', 'ethiopic', 'ethioaa' ]So for Spanish, you could do the following:
"use client"; import {type ReactNode} from "react"; import {NextUIProvider} from "@nextui-org/react"; export function AppProvider(props: AppProviderProps) { const {children, className} = props; return ( <NextUIProvider locale="es-ES" className={className}> {children} </NextUIProvider> ); } interface AppProviderProps { children: ReactNode; className?: string; }
Is there any way to change the locale using a hook?
Ihave used this -
const date = new Date("Thu Dec 26 2024 05:30:00 GMT+0530 (India Standard Time)") // date input
<I18nProvider locale="en-GB">
<DatePicker
isRequired
aria-label="date"
className="w-4/5"
minValue={parseDate(new Date().toISOString().split('T')[0])}
value={date && parseDate(date.toISOString().split('T')[0])}
onChange={(val) => setDate(new Date(val.toString()))}
/>
</I18nProvider>
problem remain same
Changing the locale in the provider updates the language of the calendar and its format. However, I need to keep the calendar localization in Swedish while ensuring the format is always DD/MM/YYYY, regardless of the language. Is there an option for this in the NextUI (HeroUI) DatePicker and DateRangePicker?
Pelase allow YYYY-MM-DD!!!
It’s great that the component automatically respects the locale, and in many cases that’s all you need, but it’s also pretty common to need to control the format beyond what’s most common in my locale.
For example, here in Norway (nb-NO) the locale default is D.M.YYYY, which is often used in informal contexts, but it’s increasingly common to use the ISO8601 format (YYYY-MM-DD), especially for things of a more technical/formal nature.
Here is an article (in Norwegian) from the Language Council of Norway, the state's consultative body on language issues, where they specifically state that YYYY-MM-DD is perfectly normal and OK in (for example) technical contexts. I think this is pretty common in other countries as well.
I would urge you to consider the locale default a suggestion and a good default to use, but it should not be the only way to control the format. My own application needs to use YYYY-MM-DD, so this is a real issue for some of us.
Is there any chance of getting this reopened? Unless I’m missing something there is still no way to change just the format - you have to change the entire locale, which is just plain wrong in many (most?) cases. Changing the format to better suit the context without changing anything else about the locale seems like a perfectly valid thing to want/need to do.
I understand that this might be a pain to support, depending on how the date picker is implemented, but it seems wrong to just point to the ability to change the locale as a solution.
