使用 react-native-community/datetimepicker 日期和时间未显示

using react-native-community/datetimepicker Date and time not showing

我是 React Native 的新手。我已经创建了一个屏幕,从那里我使用 datetimepicker 将日期和时间发送到服务器但是当我点击显示日期选择器然后日历打开但是问题是当我 select 日期然后这个 selected 日期不显示只是再次显示日期选择器按钮。时间选择器也会发生同样的情况。请帮忙 。谢谢..

这是我的代码

import React, {Component} from 'react';
import {View, Button, Platform} from 'react-native';
import DateTimePicker from '@react-native-community/datetimepicker';

export default class App extends Component {
  state = {
    date: new Date('2020-06-12T14:42:42'),
    mode: 'date',
    show: false,
  }

  setDate = (event, date) => {
    date = date || this.state.date;

    this.setState({
      show: Platform.OS === 'ios' ? true : false,
      date,
    });
  }

  show = mode => {
    this.setState({
      show: true,
      mode,
    });
  }

  datepicker = () => {
    this.show('date');
  }

  timepicker = () => {
    this.show('time');
  }

  render() {
    const { show, date, mode } = this.state;

    return (
      <View>
        <View>
          <Button onPress={this.datepicker} title="Show date picker!" />
        </View>
        <View>
          <Button onPress={this.timepicker} title="Show time picker!" />
        </View>
        { show && <DateTimePicker value={date}
                    mode={mode}
                    is24Hour={true}
                    display="default"
                    onChange={this.setDate} />
        }
      </View>
    );
  }
}

显示调整后日期的一种简单方法是将其包装在

  <Text>A simple view of dateTime: {String(this.state.date)}</Text>
  

https://snack.expo.io/WGQYSpXip