rghorbani / react-native-persian-calendar-picker

Persian Calendar Picker Component for React Native
MIT License
93 stars 26 forks source link

How can convert return date to persian? #38

Open zahrat opened 4 years ago

zahrat commented 4 years ago

I use this picker but I want to get selected date in persian not like 'Mon Jan 20 2020 19:29:15 GMT+0000' How to change this?

soheils2 commented 4 years ago

I use this picker but I want to get selected date in persian not like 'Mon Jan 20 2020 19:29:15 GMT+0000' How to change this?

ok you can install 'moment-jalaali'

its a add-on for moments.js

const JNOW = require('moment-jalaali');
import fa from "moment/src/locale/fa";
JNOW.locale("fa", fa);
JNOW.loadPersian({ usePersianDigits: true });

 function   getDate(date){
        const dte = JNOW(date).format('dddd jYY/jMM/jDD'); // or any format you wanna show
// یکشنبه 99/01/25
        const today =JNOW().format('dddd jYY/jMM/jDD');    //returns today

    }

more: https://github.com/jalaali/moment-jalaali

sam9010 commented 4 years ago

this calendar return timestamp, you can convert it and you can use to this solution: after install this https://www.npmjs.com/package/moment-jalaali you can use this package: let mydate = new Date(timestamp); var dataJalali = moment(mydate).format('jYYYY/jMM/jDD');