xgfe / react-native-datepicker

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

datepicker displays the previous date with certain years #351

Open saidhappy010 opened 5 years ago

saidhappy010 commented 5 years ago

Issue

datepicker displays the previous date with certain years

Expected Behavior

As I mention in the title, datepiker displays the date or the previous day with certain years, like 1980, 1881 and other I do not know how much. The problem is: I have a date of birth 01/01/1981. when I click on the date to modify it, the calendar appears with the date of yesterday like that 31/12/1980 instead of 01/01/ 1981. And the same thing with the year 1980. but for example with the year 2009 it works well without any problem. how can I fix this problem

DarrenHou1993 commented 5 years ago

some +1

thiemo--bleeken commented 5 years ago

same for me

vskavgaci commented 5 years ago

+1

ghost commented 4 years ago

I have the same issue. Can anybody help?

ghost commented 4 years ago

Okay, I found solution.

At first try this before date changing:

var _date =  new Date(date);
_date.setMinutes( _date.getMinutes() - _date.getTimezoneOffset());

And then if u still will have wrong dates, try this:

    constructor(props) {
        super(props);
        this.state = {
            timeZoneOffsetInHours: (-1) * (new Date()).getTimezoneOffset() / 60 
        }
    }
 <DatePicker
       ....
       timeZoneOffsetInMinutes={this.state.timeZoneOffsetInHours * 60}
       ....

As I understood the main problem in react native, this is an old date bug.

bulbul-ismail commented 4 years ago

+1

AugustusCosta commented 4 years ago

@wedusa thanks for your solution save a lot of time for me.

By the way was the only valid solution that I find.