UIDatePicker每年添加一个 [英] UIDatePicker adding one to year

查看:64
本文介绍了UIDatePicker每年添加一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常奇怪和令人困惑的问题。我找不到任何关于它的东西,这似乎是苹果的一个错误,但如果有人建议如何解决这个问题,那将会有所帮助。
有些日期使用UIDatePicker在年份中添加1,似乎永远不会低于12月27日。我已经回去几年试图找到一种模式。以下是一些示例:

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.

推荐答案

我不知道它是否会改变,但你可以尝试

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

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

这篇关于UIDatePicker每年添加一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆