xgfe / react-native-datepicker

react native datePicker component for both Android and IOS, useing DatePikcerAndroid, TimePickerAndroid and DatePickerIOS
MIT License
2.12k stars 725 forks source link

When I add "format", Preview of datepicker shows wrong year #383

Closed hinciler closed 4 years ago

hinciler commented 4 years ago

Issue

If I change format of date, preview shows wrong year. This issue only happens if I choose 50 years ago of birthday.

Expected Behavior

Which I choose date : 19.01.1952 and when I save and come back to preview of datepicker it shows. 19.01.2052

Code

    <DatePicker
           style={{width: '100%'}}
           mode="date"
           androidMode="spinner"
           date={this.state.birthday}
           placeholder='Ex: 2000-12-24'
           format="DD MMM YYYY"
           confirmBtnText="Select"
           cancelBtnText="Cancel"
           showIcon={false}
           timeZoneOffsetInMinutes={this.state.timeZoneOffsetInHours * 60}
           customStyles={{
           dateInput: {
                       borderWidth: 0,
                       width: '100%',
                       textAlign: 'center',
                       alignItems: 'flex-start',
                       borderBottomWidth: 1,
                        borderColor: "#D9DCE2",
                          },
               }}

             onDateChange={(date) => {
                         const _date = new Date(date);
                        _date.setMinutes( _date.getMinutes() - _date.getTimezoneOffset());
                         this.setState({birthday: _date});
                     }}
       />

Environment

  1. react-native -v: ^0.59.9
  2. node -v:
  3. npm -v: 6.12.0
  4. yarn --version:
  5. target platform: 28 | 13.0.2
  6. operating system: MacOS
AsABarranco commented 2 years ago

+1