Change locale in react-datepicker

后端 未结 6 1151
一向
一向 2021-02-04 03:30

I am using react-datepicker NPM package,
I tried to follow documentation but I was unable to import

registerLocale 

and

         


        
6条回答
  •  闹比i
    闹比i (楼主)
    2021-02-04 03:50

    In case you want to use a locale, that is not supported by date-fns (and those are quite few), you can do a shim.

    const monthsBG = ['Януари', 'Февруари', 'Март', 'Април', 'Май', 'Юни', 'Юли', 'Август', 'Септември', 'Октомври', 'Ноември', 'Декември'];
    const daysBG = ['нед', 'пон', 'вт', 'ср', 'четв', 'пет', 'съб'];
    
    registerLocale('bg', {
      localize: {
        month: n => monthsBG[n],
        day: n => daysBG[n]
      }, 
      formatLong:{} 
    });
    

    and then you can use this locale as any other

    
    

提交回复
热议问题