获取系统当前的时间方法如下:
//获取当前时间
NSDate *sendDate = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
[dateFormatter setDateFormat:@"yyyy年MM月dd日"];
NSString *locationString = [dateFormatter stringFromDate:sendDate];
NSLog(@"locationStringlocationString:%@",locationString);
在这里要注意的地方是,日期的格式一定要写正确,正确格式如下
yyyy-MM-dd HH:mm:ss
加入格式写错了会出现如下的错误:
YYYY年MM月dd日 这样的格式显示如下
locationStringlocationString:2016年12月28日 会出现年份不正确的现象。
YYYY年mm月DD日
locationStringlocationString:2016年42月362日
其他的格式也会显示错误的时间。