Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

justmyself

macrumors member
Original poster
Jan 2, 2009
32
0
I'm looking to get the current month in an integer. ie 0 - 11. I've spend quite bit of time on apples dev site for NSCalendarDate, but to no avail. Much frustration. Any help would be appreciated.

Thanx
 

Catfish_Man

macrumors 68030
Sep 13, 2001
2,579
2
Portland, OR
This is likely not the best way, but here's an example of something related.

Code:
NSCalender *cal = [NSCalendar autoupdatingCurrentCalendar];
NSDateComponents *comps = [cal components: NSMonthCalendarUnit fromDate:[NSDate date]];
NSInteger month = [comps month];
 

justmyself

macrumors member
Original poster
Jan 2, 2009
32
0
Yeeps, so overwhelming. I tried your example but for some reason I got a several errors. I'm hoping to find something rather strait forward.

ie.

int myVariable;

myVariable = NSCalendarDate etc... etc...


Obviously it won't be that simple, but as someone new to Objective C and Cocoa I need something quite basic. Is it just me or does Objective C and Cocoa have a steep learning curve? I've done C++, Perl, as well as JavaScript and Unix Scripting with no problems. This however just seems so twisted.
 

cazlar

macrumors 6502
Oct 2, 2003
492
11
Sydney, Australia
Is it not as simple as:
Code:
NSCalendarDate *now = [NSCalendarDate calendarDate];
int i = [now monthOfYear];
??


BTW, That should give 1-12 I believe, not 0-11


Though the above NSDateComponents code is the way to do it on iPhone, since for some reason it lacks NSCalendarDate (grrr).
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.