I need the beginning and ending of the current day in NSDate format since i have an nspredicate to get the datas between this range. so i wrote down a function to find beginning of current day and this is it
NSDate *now = [NSDate date];
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDateComponents *components = [calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit) fromDate:now];
[components setHour:0];
[components setMinute:0];
[components setSecond:0];
NSDate *start = [calendar dateFromComponents:components];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSString *strFromDate = [formatter stringFromDate:start];
when i try to nslog strFromDate it is showing the exact starting of current day like this 2013-05-05 00:00:00 +0000 but i need it in nsdate format so when i try to convert it into the nsdate like this
NSDateFormatter * dateFormat = [[NSDateFormatter alloc]init];
[dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSDate *dateStr = [[NSDate alloc]init];
dateStr = [dateFormat dateFromString:strFromDate];
and when i nslog it the result becomes 2013-05-05 18:30:00 +0000. i have tried a lot of codes and when i tried to print it in nsstring format i got the desired result do not know what goes wrong with nsdate. If anyone could guide me. Thanks in advance