一,代码。
class="cnblogs_code_copy" style="font-size: 18px">- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//2015-09-16格式
NSDate *date = [NSDate new];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd"];
NSString *dateStr = [dateFormatter stringFromDate:date];
NSLog(@"---dateStr--%@",dateStr);
}
二,输出。
2015-10-23 11:57:51.886 获得现在的时间[6826:170777] ---dateStr--
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//2015-09-16格式
NSDate *date = [NSDate new];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd"];
NSString *dateStr = [dateFormatter stringFromDate:date];
NSLog(@"---dateStr--%@",dateStr);
}