Hi guys, was wondering on how to take the current Time, and subtracting 3 hours from it to be stored in NSString?
+4
A:
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
).
Ole Begemann
2010-06-22 09:08:15
cool THanks! it works great!
Kenneth
2010-06-22 09:16:45
+4
A:
How about the [[NSDate alloc] initWithTimeIntervalSinceNow: -3*60*60]
and using an NSDateFormatter
?
king_nak
2010-06-22 09:12:11