I was trying to get the date alone (without time) from today's date using this code:
NSCalendar *cal = [NSCalendar currentCalendar];
NSDateComponents *date1Components = [cal components: NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit fromDate:[NSDate date]];
NSLog(@"Today without time :%@",[cal dateFromComponents:date1Components]);
The result is:
2014-10-14 23:01:13.398 TestViewHier[5349:60b] Today without time :2014-10-13 18:30:00 +0000
I am from India, now the time is: 2014-10-14 11:16 pm, but the result shows one day off and some random hour also.
My expected result is 2014-10-14 00:00:00
, because I need to compare this date with another date. I will get a product's expiration date from a service, and if the date is less than or equal to the current date, I need to display the products in an "Expired Products" section. I can compare the two dates by using NSDate
's comparison method.