Ghass.64 Ghass.64 - 2 months ago 6
Objective-C Question

How to get the date without Time from NSDate?

I want to get the date from

NSDate
and do not need time. Example:

NSDate* today = [NSDate date]; // want to give 20-06-2012 only


I want to get the date for today without showing the time and use it in
NSDate
variable or string variable.

Answer

In case someone else looks for this. I used the following:

NSDateComponents *components = [[NSCalendar currentCalendar] 
             components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit 
              fromDate:[NSDate date]];
NSDate *startDate = [[NSCalendar currentCalendar] 
             dateFromComponents:components];
Comments