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});
}
}
create({ container: { flex: 1, alignItems: "center", justifyContent: "center" }, }); Click on the YOUR TIME PICKER button to see the time picker.
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.
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.
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:
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'}
>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With