NSDateFormatter time format conversion, nsdateformatter format
NSString * strDate = @ "Wed Apr 20 2016 08:46:25"; NSDateFormatter * dateFomatter = [[NSDateFormatter alloc] init]; [dateFomatter setLocale: [[NSLocale alloc] initWithLocaleIdentifier: @ "en_US"]; [dateFomatter setDateFormat: @ "eee mmm dd yyyy HH: mm: ss"]; NSDate * dateFromString = [dateFomatter dateFromString: strDate]; [dateFomatter setLocale: [[NSLocale alloc] initWithLocaleIdentifier: @ "zh_cn"]; [dateFomatter setDateFormat: @ "MM-dd HH: mm: ss"]; NSString * str = [dateFomatter stringFromDate: dateFromString];
First, convert the string to the time NSDate, and then convert the time to the string in the required time format.
Note that the meaning of EEE and MMM will change with the Locale attribute of NSDateForMatter when the Locale attribute is
@ "En_US", the eee mmm represents the three-letter abbreviation of the week and month, for example, Apr.
When Locale is
@ "Zh_cn" represents the Chinese characters of the week and month, for example, Tuesday.