选择“一起"选择日期和时间.在本地反应 [英] Selecting date and time "together" in react native

查看:66
本文介绍了选择“一起"选择日期和时间.在本地反应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在,由于DatePicker不包含TimePicker,因此我倾向于使用 @ react-native-community/datetimepicker .但是,正如其文档中所写的那样,它不包含用户可以一起选择日期和时间的功能.这是他们的文档中给出的代码:

Now as DatePicker doesn't include TimePicker, I am inclined to use @react-native-community/datetimepicker. But as written in its documentation, it doesn't includes a feature with which user can select date and time together. This is the code given in their documentation:

const showDatepicker = () => {
    showMode('date');
  };

  const showTimepicker = () => {
    showMode('time');
  };

  return (
    <View>
      <View>
        <Button onPress={showDatepicker} title="Show date picker!" />
      </View>
      <View>
        <Button onPress={showTimepicker} title="Show time picker!" />
      </View>
      {show && (
        <DateTimePicker
          testID="dateTimePicker"
          value={date}
          mode={mode}
          is24Hour={true}
          display="default"
          onChange={onChange}
        />
      )}
    </View>
  );

因此,用户还必须手动单击以选择时间.要做的是选择日期后,还会提示用户选择时间,而日期时间本身存储在单个字符串中.

So with this, user will have to manually click to select time as well. What is want to do is that after selecting date, user is prompted to selected time as well and the datetime is stored in single string itself.

我找不到任何可以完成此任务的方法.请帮助我做到这一点.

I cannot find any such way to accomplish this task. please help me to do this.

编辑:这是我到目前为止所做的,但是由于无法选择时间而无法正常工作

EDIT: This is what I am doing till now, but it is not working since it cannot select time:

<DatePicker
                    style={{flex: 2, marginRight: 20}}
                    date={this.state.date}
                    format=''
                    mode="datetime"
                    placeholder="select date and Time"
                    minDate="2017-01-01"
                    confirmBtnText="Confirm"
                    cancelBtnText="Cancel"
                    customStyles={{
                    dateIcon: {
                        position: 'absolute',
                        left: 0,
                        top: 4,
                        marginLeft: 0
                    },
                    dateInput: {
                        marginLeft: 36
                    }
                    // ... You can check the source to find the other keys. 
                    }}
                    onDateChange={(date) => {this.setState({date: date})}}
                />

推荐答案

尝试使用软件包 react-native-date-picker (模式为 datetime ).它支持同时在iOS和Android上选择日期和时间.

Try using the package react-native-date-picker with mode datetime. It supports selecting date and time together on both iOS and Android.

import DatePicker from 'react-native-date-picker'
...
<DatePicker
    date={date}
    onDateChange={setDate}
    mode="datetime"
/>

这篇关于选择“一起"选择日期和时间.在本地反应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆