Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make react-native DatePickerIOS in 24 hours format?

Tags:

react-native

DatePickerIOS

I am learning react-native. How to remove AM/PM and use 24 hours 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});
  }
}
like image 264
Sanster Avatar asked Feb 13 '16 08:02

Sanster


People also ask

How do I display time picker in react-native?

create({ container: { flex: 1, alignItems: "center", justifyContent: "center" }, }); Click on the YOUR TIME PICKER button to see the time picker.

How do I render a date/time picker on iOS?

Use DatePickerIOS to render a date/time picker (selector) on iOS. This is a controlled component, so you must hook in to the onDateChange callback and update the date prop in order for the component to update, otherwise the user's change will be reverted immediately to reflect props.date as the source of truth. Inherits View Props.

How do I change the timezone used by the date picker?

By default, the date picker will use the device's timezone. With this parameter, it is possible to force a certain timezone offset. For instance, to show times in Pacific Standard Time, pass -7 * 60. Provides an initial value that will change when the user starts selecting a date.

What is the first and only argument of a date object?

The first and only argument is a Date object representing the new date and time. Maximum date. Restricts the range of possible date/time values. Example with maximumDate set to December 31, 2017:


1 Answers

Time 24h formate depend on locale props and default locale's set "en".

Add this props locale={'en_GB'}

 <DatePickerIOS
   date={new Date()}
   locale={'en_GB'}
 >
like image 60
Israt Jahan Simu Avatar answered Nov 02 '22 16:11

Israt Jahan Simu