开发者

Taking the current Time and subtracting 3 hours from it

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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜