Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
React native 如何在ReactNative中使用DateTimepicker在文本中显示日期?_React Native - Fatal编程技术网

React native 如何在ReactNative中使用DateTimepicker在文本中显示日期?

React native 如何在ReactNative中使用DateTimepicker在文本中显示日期?,react-native,React Native,我正在使用DateTimePicker,我必须显示一个日期。我要做的是,当用户单击TextView时,DateTimepicker打开,并在TextView中再次显示日期。为此,我尝试了以下方法: 日期时间选择器的代码: constructor(){ super(); this.state = { PickerValueHolder : '' , isDateTimePickerVisible: false, date: 'Birthday' } } _

我正在使用DateTimePicker,我必须显示一个日期。我要做的是,当用户单击TextView时,DateTimepicker打开,并在TextView中再次显示日期。为此,我尝试了以下方法:

日期时间选择器的代码:

constructor(){ 
  super();
  this.state = { 
    PickerValueHolder : '' ,
    isDateTimePickerVisible: false,
    date: 'Birthday'
  }
}

_showDateTimePicker = () => this.setState({ 
  isDateTimePickerVisible: true });
_hideDateTimePicker = () => this.setState({ 
  isDateTimePickerVisible: false});

_handleDatePicked = (date) => {
  this.setState({date: date})
  this._hideDateTimePicker();
};

<TouchableOpacity onPress={this._showDateTimePicker}>
  <Text style={{marginLeft:20}}>{this.state.date}</Text>
</TouchableOpacity>
<DateTimePicker
  isVisible={this.state.isDateTimePickerVisible}
  onConfirm={this._handleDatePicked}
  onCancel={this._hideDateTimePicker/>
constructor(){
超级();
this.state={
PickerValue持有者:“”,
IsDateTimePickerAvailable:false,
日期:“生日”
}
}
_showDateTimePicker=()=>this.setState({
IsDateTimePickServiceable:true});
_hideDateTimePicker=()=>this.setState({
IsDateTimePickServiceable:false});
_handleDatePicked=(日期)=>{
this.setState({date:date})
这个;
};
{this.state.date}

通过更改以下代码解决了我的问题

 _handleDatePicked = (date) => {
  var date = new Date(date);
  dobValue= isNaN(date) ? this.state.dob :date.getDate() + "/"+ 
  parseInt(date.getMonth()+1) +"/"+ date.getFullYear();
    if (! isNaN(date)) {
    this.setState({ dob: dobValue });
  }
  this._hideDateTimePicker();
  };

通过更改以下代码解决了我的问题

 _handleDatePicked = (date) => {
  var date = new Date(date);
  dobValue= isNaN(date) ? this.state.dob :date.getDate() + "/"+ 
  parseInt(date.getMonth()+1) +"/"+ date.getFullYear();
    if (! isNaN(date)) {
    this.setState({ dob: dobValue });
  }
  this._hideDateTimePicker();
  };