react-native - 如何以 24 小时格式制作 React-native DatePickerIOS?

标签 react-native

DatePickerIOS

我正在学习 react 原生。如何在 DatePickerIOS 中删除 AM/PM 并使用 24 小时格式?

这是我的代码

class ClockScreen extends React.Component {
  constructor(props){
    super(props);
    this.state = {
      date: new Date(),
      timeZoneOffsetInHours: (-1) * (new Date()).getTimezoneOffset() / 60,
    };
  }

  render() {
      return (
        <View style={styles.container}>
          <DatePickerIOS
            date={this.state.date}
            mode="time"
            timeZoneOffsetInMinutes={this.state.timeZoneOffsetInHours * 60}
            onDateChange={this.onDateChange.bind(this)}
          />
        </View>
      );
  }

  onDateChange(date) {
    this.setState({date: date});
  }
}

最佳答案

时间 24 小时格式取决于语言环境 Prop 和默认语言环境的设置“en”。

添加这个 Prop locale={'en_GB'}

 <DatePickerIOS
   date={new Date()}
   locale={'en_GB'}
 >

关于react-native - 如何以 24 小时格式制作 React-native DatePickerIOS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35377590/

相关文章:

android - TextInput selectionColor 属性在 android 上没有改变颜色

android - 我可以在 React Native 中要求专门针对 iOS 的模块吗?

ios - 为什么特定站点在 React Native Webview 中显示为 "Error"?

reactjs - 长坐标数组中的 Redux 性能。我需要获取一个巨大数组上的所有坐标以在 map 中显示

android - 使用 expo build 读取 ECONNRESET

javascript - Prop 未显示在新 route

ios - 已选择和未选择状态的 react 导航中的不同 tabBar 图标?

react-native - 如何使用 Expo 将图像保存到相机胶卷?

android - 尝试运行android项目时出现问题

image - 如何在android中使用不同像素比的android图像?我应该为 hdpi 图像使用什么我不能使用 imageName@1.5x?