本文转载至 http://www.baidu.com/link?url=dcQWiL1FD_She6P4RM2IvEeJas0_gtG3LkRNTV5H87X0AyKCHvwYjBz2hdcB2JVpTyMRhl6Hno2FX_U3TEDgZq
//1),创建一个对象,赋值为当前日期date 创建的NSDate对象,获得的永远是0时区的时间,china是东八区,需要加上8个小时
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);