Thursday, June 28, 2012

Get Month from NSDate

In this example we will take todays date and find the month in todays date.



    NSDate *today=[NSDate date];
    
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"M"];
    NSString *currentMonth = [dateFormatter stringFromDate:today];
    //currentMonth will be 1 for Jan, 2 for Feb etc
    NSLog(@"currentMonth=%@",currentMonth);


    [dateFormatter release];
    

No comments:

Post a Comment