问题描述
从'时刻'导入时刻;
const { selectedStartDate } = this.state;
const startDate = selectedStartDate ? selectedStartDate.toString() : '';
const maxDate = moment(selectedStartDate,'DD-MM-YYYY').format();
我得到的输出是
2021 年 2 月 8 日星期一 12:00:00 GMT+0530
2021-02-08T12:00:00+05:30
解决方法
试试这个
const maxDate = moment(selectedStartDate).format('DD/MM/YYYY');
,
我自己尝试得到了答案......可能会帮助像我这样的人......在此处发布代码。
import moment from 'moment';
//code to pick date into selectedStartDate here
const { selectedStartDate } = this.state;
const maxDate = moment(selectedStartDate).format('DD-MM-YYYY');
//write your calendar-picker code here
<View>
<Text style={styles.details}>{ maxDate }</Text>
</View>
输出:05-02-2021