How to make a DatePickerIOS return date in 24 hours format?

DatePickerIOS

I am learning to respond natively. How to remove AM / PM and use 24 hour format in DatePickerIOS?

Here is my code

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});
  }
}
+5
source share
2 answers

You can achieve this using this library - https://github.com/milasevicius/react-native-timepicker .

0
source

I ran into this problem, so I created my own library https://github.com/NYSamnang/react-native-24h-timepicker

Image Preview Here

0
source

Source: https://habr.com/ru/post/1628613/


All Articles