微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

我在 react native 中使用 react-native 日历选择器我想要日期格式 DD/MM/YYYY 作为输出

如何解决我在 react native 中使用 react-native 日历选择器我想要日期格式 DD/MM/YYYY 作为输出

从'时刻'导入时刻;

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。