//创建一个日期对象
NSDate *date=[NSDate date];
NSLog(@"%@",date);
//以0时区为基准,便宜某个时间间隔.
NSDate *nowDate=[NSDate dateWithTimeIntervalSinceNow:(60*60*8)];
//计算两个时间的间隔,单位:秒.
NSTimeInterval timeInterVal=[nowDate timeIntervalSinceDate:date];
NSLog(@"%lf",timeInterVal);
NSLog(@"%@",nowDate);
//知道某个时间,偏移多少秒
NSDate *date1=[NSDate dateWithTimeInterval:60 sinceDate:nowDate];
NSLog(@"%@",date1);
//某个给定的时间加上偏移量.
NSDate *date2=[nowDate dateByAddingTimeInterval:60];
NSLog(@"%@",date2);
NSDate *date=[NSDate date];
NSLog(@"%@",date);
// NSDateFormatter
//创建一个时间格式对象
NSDateFormatter *dateFormatter=[[NSDateFormatter alloc] init];
//设置格式
[dateFormatter setDateFormat:@"yyyy日MM月dd HH:mm:ss"];
//将某个时间按照我们给定的时间格式转换成字符串,并自动检测时区
NSString *s= [dateFormatter stringFromDate:date];
NSLog(@"%@",s);
//将字符串转换为NSDate
NSDate *s2= [dateFormatter dateFromString:@"2012日12月12 12:12:12"];
NSLog(@"%@",s2);