I\'m trying to write a simple function using Objective C that accepts an NSDate object and returns an NSDate object that contains the same date value but has removed any tim
Try this:
-(NSDate *)dateWithOutTime:(NSDate *)datDate {
if( datDate == nil ) {
datDate = [NSDate date];
}
NSDateComponents* comps = [[NSCalendar currentCalendar] components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit fromDate:datDate];
return [[NSCalendar currentCalendar] dateFromComponents:comps];
}
-(NSDate *)dateWithOutTime:(NSDate *)datDate{
if( datDate == nil ) {
datDate = [NSDate date];
}
NSDateComponents* comps = [[NSCalendar currentCalendar] components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit|NSHourCalendarUnit|NSMinuteCalendarUnit|NSSecondCalendarUnit fromDate:datDate];
[comps setHour:00];
[comps setMinute:00];
[comps setSecond:00];
[comps setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
return [[NSCalendar currentCalendar] dateFromComponents:comps];
}