一,代碼。 二,輸出。 - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. //2015-09-16格式 NSDate ...
一,代碼。
- (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);
}