【问题标题】:DatePicker NativeBase - Format of the picked dateDatePicker NativeBase - 选择日期的格式
【发布时间】:2018-06-26 10:28:15
【问题描述】:

我正在使用 DatePickerNativeBase 并希望在选择日期后更改显示日期的格式。由于缺少文档,我无法找到相关的道具。

有没有办法可以使用format="YYYY-MM-DD" 更改DatePickerAndroid 中的日期格式?

【问题讨论】:

标签: react-native datepicker react-native-android native-base


【解决方案1】:

在本机基础 v2.6.1 及更高版本中已修复。

<DatePicker
formatChosenDate={date => {return moment(date).format('YYYY-MM-DD');}}
..... />

【讨论】:

    【解决方案2】:

    试试这个:----

    async onPressAction() {
        try {
        const {action, year, month, day} = await DatePickerAndroid.open({
          // Use `new Date()` for current date.
          // May 25 2020. Month 0 is January.
          date: new Date(2018, 6, 26)
        });
        if (action !== DatePickerAndroid.dismissedAction) {
          // Selected year, month (0-11), day
          var date = new Date(year, month, day);
          var year = date.getFullYear();
          var month = date.getMonth()+1;
          var day = date.getDate();
          console.log('>>>>>>>>>>>>>'+year);
          console.log('>>>>>>>>>>>>>'+month);
          console.log('>>>>>>>>>>>>>'+day);
          console.log(year+'-'+month+'-'+day);
    
        }
      } catch ({code, message}) {
        console.warn('Cannot open date picker', message);
      }
    }
    

    【讨论】:

    • 我实际上想要一些与 'NativeBase' 'DatePicker' 相关的东西。无论如何感谢您的回答!
    猜你喜欢
    • 2021-12-06
    • 1970-01-01
    • 1970-01-01
    • 2014-02-17
    • 1970-01-01
    • 1970-01-01
    • 2014-04-22
    • 2019-08-11
    • 2015-03-13
    相关资源
    最近更新 更多