Moj*_*ehr 5 javascript reactjs react-dates
我正在尝试使用带有非英语语言环境(波斯语)的airbnb react-dates并且一切正常,除了当月的第一天。
月份不是从波斯 (Jalaali) 历法的第一天开始到第 30 天,而是从当月的第 10 天开始并持续到下个月的第 10 天。
这个问题甚至存在于他们的例子中。我想知道是否有任何方法可以解决这个问题。
我一直在一个项目中处理这个问题,这个问题目前是爱彼迎反应日期中的一个开放问题。为了解决这个问题,我分叉了原始项目,以便它可以与 jalali moment 一起使用,并且月份从正确的日期开始,github 和 npm 存储库的链接是:
如何使用:
import momentJalali from 'moment-jalaali'
在要使用 datepicker 的组件的构造函数中设置适当的区域设置:
momentJalali.locale('fa')
从分叉存储库导入日期选择器:
import {SingleDatePicker,DateRangePicker} from "react-dates-jalali";
在渲染部分中,按以下方式使用singdatepicker:
<SingleDatePicker
date={date} //momentDate if you have not set this property,it automatically sets to today
focused={this.onFocusChange}//function change focused:open-close
onFocusChange={.../function}
showClearDate={true}
required={true}
isRTL={true}
monthFormat={monthFormat}//for persian:'jMMMM jYYYY', for english :'MMMM YYYY'
onDateChange={this.onDateChange}//function set your date Change
/>
Run Code Online (Sandbox Code Playgroud)在渲染部分中,按以下方式使用 daterangepicker:
<DateRangePicker
startDate={startDate} //moment startDate if you have not set this property,it automatically sets to today
endDate={endDate} //moment endDate
onFocusChange={.../function}
required={true}
isRTL={true}
onDatesChange={this.onDatesChange}//function set startDate and endDate
focusedInput={focusedInput}//similar to airbnb api-open\close
showClearDates={true}
monthFormat={monthFormat}//for persian:'jMMMM jYYYY', for english :'MMMM YYYY'
/>
Run Code Online (Sandbox Code Playgroud)不用说,这个存储库支持此处未提及的所有其他 Airbnb 反应日期 api。
如果您的网站是多语言的,并且您可以随时更改区域设置和月份格式,您也可以使用此存储库。