Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIDatePicker adding one to year

I have a very strange and confusing problem. I can't find anything about it and it seems like a bug with Apple, but if anyone has a suggestion on how to get around this it would be helpful. There are certain dates that are adding 1 to the year with a UIDatePicker, seems to never be less than December 27th. I've went back a few years to try and find a pattern. Here are some examples:

Any date picked >= December 28th in 2014 changes to 2015
>= 29th in 2013 -> 2014
>= 30th in 2012 -> 2013
2011 (issue doesn't occur)
>= 26th in 2010 -> 2011
>= 27th in 2009 -> 2010
>= 28th in 2008 -> 2009
>= 30th in 2007 -> 2008
=  31st in 2006 -> 2007
2005  (issue doesn't occur)
>= 26th in 2004 -> 2005
>= 28th in 2003 -> 2004
>= 29th in 2002 -> 2003
>= 30th in 2001 -> 2002
=  31st in 2000 -> 2001
=  31st in 1999 -> 2000
>= 27th in 1998 -> 1999
>= 28th in 1997 -> 1998
>= 29th in 1996 -> 1997
=  31st in 1995 -> 1996
1994  (issue doesn't occur)

Hopefully that's not too confusing. I can't seem to find a definitive pattern and can't figure out how to get around this issue. Here is the code I'm using to retrieve the date from the picker:

NSString *date;
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"YYYY-MM-dd"];
date = [formatter stringFromDate:datePicker.date];

Any help on this would be greatly appreciated.

like image 726
Brian Tacker Avatar asked Feb 10 '26 23:02

Brian Tacker


1 Answers

I don´t know if it would change anything but you could try

[formatter setDateFormat:@"yyyy:MM:dd"];

like image 140
Pierre Avatar answered Feb 13 '26 14:02

Pierre



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!