DatePicker returns wrong year for Jan 1

后端 未结 1 857
小鲜肉
小鲜肉 2021-01-23 18:38

I have a DatePicker control in my app. If I try to choose, for example, Jan 1, 2011, it returns Jan 1, 2010. If I choose Jan 1, 2040, I get Jan 1, 2039, and so on. Dec 31 and

相关标签:
1条回答
  • 2021-01-23 19:19

    if daycount is truly 0 like you say in your comment, then that's likely the source of your problem. The day property of an NSDateComponents object should be in the natural range as defined by the calendar. In the case of the Gregorian calendar, that is 1-31. If the day is outside of that range, then units start wrapping around and you'll probably not get the result you want.

    0 讨论(0)
提交回复
热议问题