Utilities:
One can import and use these two functions to convert Gregorian date to Jalali date and vice versa.
These functions accept date object as the first argument and divider sign as the second argument ('/' is the default value).
convertToFa( dateObj, '/' )
import DtPicker, {
convertToFa
} from 'react-calendar-datetime-picker'
const DatePicker = () => {
const [date, setDate] = useState(null)
return (
<div>
<DtPicker
onChange={setDate}
/>
<p>{convertToFa(date)}</p>
</div>
)
}
export default DatePicker
value:
null
converted value:
""
convertToEn(dateObj, '-')
import DtPicker, {
convertToEn
} from 'react-calendar-datetime-picker'
const DatePicker = () => {
const [date, setDate] = useState(null)
return (
<div>
<DtPicker
onChange={setDate}
withTime
local="fa"
/>
<p>{convertToEn(date,'-')}</p>
</div>
)
}
export default DatePicker
value:
null
converted value:
""