Thanks for the insights. Currently I have a chunk of code in a loop that looks like this:
*//'pointer' increments in a loop - so create a date for each month of the year, c defined outside the loop* int currentYear = [comp year]; NSDateComponents *components = [[[NSDateComponents alloc]init] autorelease]; [components setMonth:pointer+1]; [components setDay:1]; [components setYear:currentYear]; NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; NSDate *myDate = [gregorian dateFromComponents:components]; NSRange range = [c rangeOfUnit:NSDayCalendarUnit inUnit:NSMonthCalendarUnit forDate:[c dateFromComponents:components]]; *//Now get the day of the week the 1st day of this month falls on (ie. 6 = Friday)* unsigned uFlags = NSWeekdayCalendarUnit; NSDateComponents *comp2 = [gregorian components:uFlags fromDate:myDate]; NSLog(@"Date: %@, days in this month: %d, starts on weekday:%i", myDate, range.length, [comp2 weekday] ); And the output looks like this: *Date: 2010-01-01 00:00:00 -0500, days in this month: 31, starts on weekday:6* *Date: 2010-02-01 00:00:00 -0500, days in this month: 28, starts on weekday:2* *Date: 2010-03-01 00:00:00 -0500, days in this month: 31, starts on weekday:2* *Date: 2010-04-01 00:00:00 -0400, days in this month: 30, starts on weekday:5* *Date: 2010-05-01 00:00:00 -0400, days in this month: 31, starts on weekday:7* *Date: 2010-06-01 00:00:00 -0400, days in this month: 30, starts on weekday:3* *Date: 2010-07-01 00:00:00 -0400, days in this month: 31, starts on weekday:5* *Date: 2010-08-01 00:00:00 -0400, days in this month: 31, starts on weekday:1* *Date: 2010-09-01 00:00:00 -0400, days in this month: 30, starts on weekday:4* *Date: 2010-10-01 00:00:00 -0400, days in this month: 31, starts on weekday:6* *Date: 2010-11-01 00:00:00 -0400, days in this month: 30, starts on weekday:2* *Date: 2010-12-01 00:00:00 -0500, days in this month: 31, starts on weekday:4* I'll rename some of the stuff & check into that number of months in a year thing. Thanks again. On Mon, Jan 4, 2010 at 2:17 PM, Nick Zitzmann <n...@chronosnet.com> wrote: > > On Jan 4, 2010, at 11:35 AM, Eric E. Dolecki wrote: > > > I am creating an iPhone view that has 12 months of views in it starting > with > > January. > > Don't make assumptions about calendars unless you are absolutely sure you > can get away with them, e.g. every calendar currently in use in the world > uses seven day weeks. In this case, you shouldn't, because, for example, > while it's true that most calendar types have exactly 12 months in a year, > the Hebrew calendar has 12 months in a regular year and 13 months in a leap > year. You can use NSCalendar to figure out how many months there are in a > given year. > > > For each subview (month) I need to get the 1st day of the month (which > > calendar day it falls on as an int). For instance Jan 2010 begins on a > > Friday (int of 5 I assume). > > Again, use NSCalendar and NSDateComponents. They are available on the > iPhone OS; the older NSCalendarDate class is not available on the iPhone OS. > > Nick Zitzmann > <http://www.chronosnet.com/> > > -- http://ericd.net Interactive design and development _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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 arch...@mail-archive.com