一,代码。
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. //调用获得现在日期的函数。 [self getDateFromLocal]; } #pragma -mark -functions //获得现在的日期。格式:2015-03-11 -(NSString*)getDateFromLocal{ NSDate * senddate=[NSDate date]; NSDateFormatter *dateformatter=[[NSDateFormatter alloc] init]; [dateformatter setDateFormat:@"YYYY-MM-dd"]; NSString * locationString=[dateformatter stringFromDate:senddate]; NSLog(@"locationString:%@",locationString); return locationString; }
二,输出。
2015-10-19 13:42:54.112 获得现在的日期[5520:126089] locationString:2015-10-19