NSDate *currentDate = [NSDate date];//获取当前时间,日期NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];[dateFormatter setDateFormat:@"YYYY/MM/dd hh:mm:ss SS"];NSString *dateString = [dateFormatter stringFromDate:currentDate];NSLog(@"dateString:%@",dateString);
This will show the date and time in the prescribed format.
dateString:2015/01/03 08:01:20 24Description of the meaning of the corresponding format
YYYY (year)/mm (month)/DD (day) HH (hours): MM (min): ss (SEC) SS (MS)
You need to use whichever word you want to add to the format.
It is worth noting that if you want to display two-digit years, you can use "YY/MM/DD hh:mm:ss ss" and two Y for two-digit years.
Also the uppercase m and the lowercase m represent different meanings. "M" represents the month, "m" Code minutes
"HH" stands for 24-hour, "HH" stands for 12-hour system
Get today's time and return in the prescribed format