Reputation: 3986
What I did, value.getTime is not a function
error seem to come from the onChange
<DateTimePicker
style={{width: '80%', height: 50}}
testID="dateTimePicker"
value={values.date}
mode="datetime"
is24Hour={true}
display="default"
onChange={(date) => {
setValues({...values, ['date']: date});
}}/>
Upvotes: 2
Views: 3926
Reputation: 669
Go to node_modules/@react-native-community/datetimepicker/src
In
DatatimePicker.android.js line No:88
DatatimePicker.ios.js line No:69
files change following
const timestamp = value.getTime();
to
const timestamp = Date.parse(value)
getTime() is only apply on New Date()
format
Upvotes: 1
Reputation: 502
I'd try: value={new Date(values.date)}
PS: event is also required as the first parameter in onChange
onChange={(event, date) => {
setValues({...values, ['date']: date});
}}
Upvotes: 1
Reputation: 3986
Turn out I also need to pass in the event
as the param on onChange even if it is not used.
onChange={(event, date) => {
setValues({...values, ['date']: date});
}}
Full block:
<DateTimePicker
style={{width: '80%', height: 50}}
testID="dateTimePicker"
value={values.date}
mode="datetime"
is24Hour={true}
display="default"
onChange={(event, date) => {
setValues({...values, ['date']: date});
}}
/>
Note: HotReload will still throw error when add event
param, will require a Reload/Restart to fix it.
Upvotes: 3