ios代码实现时间设置NSDate
本文转载至 http://www.baidu.com/link?url=dcQWiL1FD_She6P4RM2IvEeJas0_gtG3LkRNTV5H87X0AyKCHvwYjBz2hdcB2JVpTyMRhl6Hno2FX_U3TEDgZq
NSDate *date = [NSDate date];
NSTimeZone *zone = [NSTimeZone systemTimeZone];//修改时区
NSInteger interval1 = [zone secondsFromGMTForDate: date];//修改时区
NSDate *localDate1 = [date dateByAddingTimeInterval: interval1];//修改时区
NSLog(@"今天%@", localDate1);
//2),创建一个明天此时的日期(时间间隔是以秒为单位的)dateWithTimeIntervalSinceNow:
NSDate *tomorrow = [NSDate dateWithTimeIntervalSinceNow:24 * 60 * 60];
NSInteger interval2 = [zone secondsFromGMTForDate: tomorrow];
NSDate *localDate2 = [tomorrow dateByAddingTimeInterval: interval2];
NSLog(@"明天%@", localDate2);
//3),创建一个昨天此时的日期
NSDate *yesterday = [NSDate dateWithTimeIntervalSinceNow:-24 * 60 * 60];
NSInteger interval3 = [zone secondsFromGMTForDate: yesterday];
NSDate *localDate3 = [yesterday dateByAddingTimeInterval: interval3];
NSLog(@"昨天%@", localDate3);