Function
- (NSDate *)strictDateFromDate:(NSDate *)date{
NSUInteger flags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit;
NSDateComponents *components = [[NSCalendar currentCalendar] components:flags
fromDate:[NSDate date]];
NSString *stringDate = [NSString stringWithFormat:@"%ld/%ld/%ld", (long)components.day, (long)components.month, (long)components.year];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.dateFormat = @"dd/MM/yyyy";
NSDate *DateNS = [formatter dateFromString:stringDate];
NSLog(@"Date Calendar did select String Type: %@",stringDate);
NSLog(@"Date Calendar did select Date Type: %@",DateNS);
return [formatter dateFromString:stringDate];
}
Result
Date Calendar did select String Type: 26/2/2015
Date Calendar did select Date Type: 2015-02-25 17:00:00 +0000
but the result are not equal.How to solve to make it equal. How to make it have same date and I do not care about the format of the date but I need date without time.
Aucun commentaire:
Enregistrer un commentaire