Hi,
Apologies in advance for what I think must be a basic question. It's something
I've never had cause to do before, assumed must be fairly straightforward, and
then seemed a lot more complicated than it should be which leads me to think
that I am using the wrong search terms...
All I want to do is this: I would like to generate the names of all the months
for a specified year. Then for each month in that year, I would like to
generate the names of every day. For instance:
2009
- January
-- Thursday, 1st January 2009
-- Friday, 2nd January 2009
... and so on
- February
-- ... etc.
I seem to be looking in the wrong areas in the frameworks, though. I thought
NSDate and NSCalendar would be the place to look, but both seem overly
complicated for this purpose. As far as I can see, in order to use NSCalendar
to do this, I would have to do the following:
1) Start with a January NSDate in the specified year.
2) Get number of months for that year using [calendar
rangeOfUnit:NSMonthCalendarUnit inUnit:NSYearCalendarUnit forDate:january]
(given that the app is only for personal purposes for now, I could just assume
12 for this part).
3) Get number of days in each month by using [calendar
rangeOfUnit:NSDayCalendarUnit inUnit:NSMonthCalendarUnit forDate:january] and
then adding on a month (though how to do that? - NSTimeInterval is in seconds
and there are different numbers of days in each month...) to get the number of
days for each month.
4) Use NSDateFormatter to format the date for display (I'll have to do that
part no matter what method I use).
Steps 1-3 seem needlessly complicated and error-prone, though, which leads me
to suspect I am taking completely the wrong approach and missing the blindingly
obvious. Is there a better way of doing this?
Many thanks in advance for any help or pointers.
All the best,
Keith
_______________________________________________
Cocoa-dev mailing list ([email protected])
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]