views:

44

answers:

2

Say I have the following:

NSDate *today = [NSDate date];

How do I just the get integer value for the month? day? or year?

+1  A: 

You want this NSDateCOmponenets

specifically:

- (NSDateComponents *)components:(NSUInteger)unitFlags  fromDate:(NSDate *)date
ennuikiller
comps is never defined here? I am just looking to split the current date into parts, seems so complex for such a simple thing
Slee
welcome to objective-c!
ennuikiller
+1  A: 

Or you could just use the NSDate class:

NSDate *date = [NSDate date];
    int month = [[date descriptionWithCalendarFormat:@"%m" timeZone:nil locale:nil] intValue];
    int day = [[date descriptionWithCalendarFormat:@"%d" timeZone:nil locale:nil] intValue];
    int year = [[date descriptionWithCalendarFormat:@"%Y" timeZone:nil locale:nil] intValue];

    NSLog(@"Today: %i-%i-%i", year, month, day);

Hope it works, ief2

Ief2
that's exactly what I was looking for!
Slee