tags:

views:

20

answers:

1

I have two queries... I am about to write a custom DatePicker where in could control the number of components as well. Like Date and Month only and no Year.

Q1) Do you have any custom code already available which takes care of leap year logic? Q2) I thought of writing separate arrays of days... but writing numbers from 1 to 31 and then then repeating it for different months is annoying. Any better solution here?

+1  A: 

Do yourself a favor and don't write your own date algorithms. NSCalendar and NSDateComponents can probably do everything you need. And using the APIs provided by the system also ensures that your code works in many different locale settings.

For example, to retrieve the number of days in a month, call [myCalendar rangeOfUnit:NSDayCalendarUnit inUnit:NSMonthCalendarUnit forDate:myDate].

Ole Begemann