// 创建NSDate对象
NSDate *nowDate1 = [NSDate date];
NSDate *nowDate2 = [[NSDate alloc]init];
NSDate *nowDate3 = [[NSDatealloc]initWithTimeIntervalSinceNow:7 *60 * 60];
NSLog(@"%@",nowDate1);
NSLog(@"%@",nowDate2);
NSLog(@"%@",nowDate3);
//NSDateFormatter
NSDateFormatter *date4 = [[NSDateFormatteralloc]init];
//设置格式
[date4 setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
//设置时区
[date4 setTimeZone:[NSTimeZonetimeZoneForSecondsFromGMT:8 * 3600]];
//[date4 setTimeZone:[NSTimeZone timeZoneWithName:@"Asia/Los_Angeles"]];
//时间类型转换成字符串类型
NSString *now = [date4 stringFromDate:[NSDatedate]];
NSString *now1 = [date4 stringFromDate:nowDate3];
NSLog(@"~~~~~~~%@",now1);
NSLog(@"现在是%@",now);
// 使用NSDate的category
NSString *d = [NSDate getDatestr];
NSLog(@"%@", d);
原文地址:http://www.cnblogs.com/mingtiannihao/p/3721043.html