question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

time picker always return invalid date

See original GitHub issue

react-native-modal-datetime-picker: “^6.0.0”, react-native: “0.55.4”

Platform: Android

handleTimePicked = (time) => {
    console.log(time);    // Invalid date
    this.hideTimePicker();
  };

<DateTimePicker
        mode='time'
        date={new Date(this.state.selectedTime)}
        isVisible={this.state.isTimePickerVisible}
        onConfirm={this.handleTimePicked}
        onCancel={this.hideTimePicker}
      />

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:7

github_iconTop GitHub Comments

2reactions
vshalvaghasiyacommented, Aug 22, 2018

import DateTimePicker from ‘react-native-modal-datetime-picker’; import moment from ‘moment’;

constructor(props) { super(props); this.state = { selectedDate: moment(new Date()).format(‘DD-MM-YYYY’), selectedTime: moment(new Date()).format(‘HH:mm’), }; }

handleDatePicked = (date) => { const newDate = moment(new Date(date.toString().substr(0, 16))).format(‘DD-MM-YYYY’); this.setState({ selectedDate: newDate }); this.hideDatePicker(); };

<DateTimePicker date={new Date(this.state.selectedDate)} isVisible={true/false} onConfirm={this.handleDatePicked} onCancel={this.hideDatePicker} />

1reaction
nsisodiyacommented, Aug 22, 2018

@VKGraphics

worked, like this

Yup, worked,

state = {
    isDateTimePickerVisible: false,
    selectedDate: '07:00 AM'
};

render() {
    return (
      <Container>
        <Text style={{color: 'white'}}>This is SunRise Screen</Text>
        <TouchableOpacity onPress={this.showDateTimePicker}>
          <Text>Show DatePicker</Text>
        </TouchableOpacity>
        <Text>{this.state.selectedDate}</Text>
        <DateTimePicker
          mode="time"
          date={moment(`2000/10/1 ${this.state.selectedDate}`).toDate()}
          is24Hour={true}
          isVisible={this.state.isDateTimePickerVisible}
          onConfirm={this.handleDatePicked}
          onCancel={this.hideDateTimePicker}
        />
      </Container>
    );
  }
Read more comments on GitHub >

github_iconTop Results From Across the Web

JavaScript invalid date from DateTime Picker - Stack Overflow
But your expected date is Day/Month/Year. For example, the date 04/12/2017 is returning April 12th instead of December 4th. You can use a...
Read more >
A date from the Date Picker is an invalid date!
Datepicker returning time. Teodor November 26, 2021, 1:04pm #2. The validator expects a date in yyyy-mm-dd or yyyy/mm/dd format.
Read more >
RangeError: invalid date - JavaScript - MDN Web Docs
The JavaScript exception "invalid date" occurs when a string leading to an invalid date has been provided to Date or Date.parse() .
Read more >
How to prevent entering an invalid date for the ... - IBM
The Date Time Picker BPM UI control is not working as expected. When you first select a date from Date Time Pickerand then...
Read more >
Invalid Date from Date picker in Mobile App - ServiceNow
Our default date format has always been set to MM-dd-yyyy. But when we select the Date/Time field and pick a date from the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found