I'm trying to make a shortcut that says how many days are left before the event. I want to calculate the difference between today's date and the date of events. I use this code and give me -4600. It works fine until I use today's date.
NSDateFormatter *f = [[NSDateFormatter alloc] init]; [f setDateFormat:@"yyyy-MM-dd"]; NSDate *startDate = [NSDate date]; NSDate *endDate = [f dateFromString:end]; NSCalendar *gregorianCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; NSDateComponents *components = [gregorianCalendar components:NSDayCalendarUnit fromDate:startDate toDate:endDate options:0]; return components.day; return components.day;
ios objective-c nsdate nsstring
user1898829
source share