was wondering on how 开发者_开发技巧to take the current Time, and subtracting 3 hours from it to be stored in NSString?
NSDate *now = [NSDate date];
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *comps = [[NSDateComponents alloc] init];
[comps setHour:-3];
NSDate *threeHoursAgo = [calendar dateByAddingComponents:comps toDate:now options:0];
[comps release];
[calendar release];
I leave the output as an NSString
to you (use NSDateFormatter
).
How about the [[NSDate alloc] initWithTimeIntervalSinceNow: -3*60*60]
and using an NSDateFormatter
?
精彩评论