nextui icon indicating copy to clipboard operation
nextui copied to clipboard

[Feature Request] Date Picker support for dd/mm/yyyy and yyyy/mm/dd

Open Armandotrsg opened this issue 2 years ago • 13 comments

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 avatar Apr 19 '24 00:04 Armandotrsg

@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.

MartaBento avatar Apr 19 '24 08:04 MartaBento

@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?

getellez avatar Apr 19 '24 21:04 getellez

@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>

CleanShot 2024-04-20 at 12 33 03@2x

Armandotrsg avatar Apr 20 '24 18:04 Armandotrsg

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;
}

jrgarciadev avatar Apr 24 '24 13:04 jrgarciadev

@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>

CleanShot 2024-04-20 at 12 33 03@2x

This dosnt work for me, i want to be able to get formatt the Input like this mm/yyyy

tjfaith avatar Jun 01 '24 10:06 tjfaith

how do i get only month and year, i need to formatt it like this mm/yyyy, there should be a dateFormat props

tjfaith avatar Jun 01 '24 10:06 tjfaith

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;
}

Is there any way to change the locale using a hook?

maxtsh avatar Aug 05 '24 21:08 maxtsh

Screenshot 2024-12-15 094657

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

arit98 avatar Dec 15 '24 04:12 arit98

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?

fahry-mohammed avatar Jan 21 '25 08:01 fahry-mohammed

Pelase allow YYYY-MM-DD!!!

intermarkec avatar Feb 08 '25 23:02 intermarkec

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.

stiang avatar Mar 17 '25 19:03 stiang

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.

stiang avatar Aug 12 '25 11:08 stiang