Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the day component out of an NSDate?

Tags:

iphone

nsdate

I have an NSDate object and need an integer of the day. i.e. if we have 25th May 2010, the int should be 25. Is there a simple way to do it?

like image 626
dontWatchMyProfile Avatar asked Nov 27 '22 23:11

dontWatchMyProfile


1 Answers

Please consider this post on how to get calendar components from an NSDate. Essentially it will look something like:

NSCalendar*       calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents* components = [calendar components:NSDayCalendarUnit
                                           fromDate:myDate];
NSInteger         day = [components day];

(Don't forget memory management for the above.)

like image 97
fbrereto Avatar answered Dec 09 '22 14:12

fbrereto