react-native-datepicker icon indicating copy to clipboard operation
react-native-datepicker copied to clipboard

datepicker displays the previous date with certain years

Open saidhappy010 opened this issue 6 years ago • 7 comments

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

saidhappy010 avatar Jul 24 '19 10:07 saidhappy010

some +1

DarrenHou1993 avatar Aug 07 '19 08:08 DarrenHou1993

same for me

thiemo--bleeken avatar Aug 23 '19 06:08 thiemo--bleeken

+1

vskavgaci avatar Aug 31 '19 18:08 vskavgaci

I have the same issue. Can anybody help?

ghost avatar Oct 08 '19 06:10 ghost

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.

ghost avatar Oct 08 '19 11:10 ghost

+1

bulbul-ismail avatar Jan 05 '20 12:01 bulbul-ismail

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

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

AugustusCosta avatar Apr 17 '20 11:04 AugustusCosta