代码之家  ›  专栏  ›  技术社区  ›  Hasangi

datepicker nativebase-所选日期的格式

  •  0
  • Hasangi  · 技术社区  · 8 年前

    我正在使用 DatePicker 属于 NativeBase 并希望在选择日期后更改显示日期的格式。由于缺少文件,我找不到相关的道具。

    有没有办法把日期的格式改成 DatePickerAndroid 使用 format="YYYY-MM-DD" ?

    1 回复  |  直到 8 年前
        1
  •  1
  •   Newana    7 年前

    在本机基础版本2.6.1以后的版本中修复。

    <DatePicker
    formatChosenDate={date => {return moment(date).format('YYYY-MM-DD');}}
    ..... />
    
        2
  •  0
  •   Pramod    8 年前

    试试这个:

    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);
      }
    }
    
    推荐文章