如题:
如何将"yyyy年mm月dd日"的字符串 转换为 "yyyy-mm-dd"格式的字符串?
原谅我是iOS新手吧,非常感谢
学习是最好的投资!
NSString *strSrcDate=@"2016年2月1日"; NSTimeZone *timeZone=[NSTimeZone timeZoneWithAbbreviation:@"GMT"]; NSDateFormatter *fmt=[[NSDateFormatter alloc]init]; fmt.dateFormat = @"yyyy年MM月dd日"; fmt.timeZone = timeZone; NSDateFormatter *dstFmt=[[NSDateFormatter alloc]init]; dstFmt.dateFormat = @"yyyy-MM-dd"; dstFmt.timeZone = timeZone; NSDate *srcDate=[fmt dateFromString:strSrcDate]; NSLog(@"date converted from %@ to %@",strSrcDate,[dstFmt stringFromDate:srcDate]);
If they are all strings, direct string replacement is the fastest.
If they are all strings, direct string replacement is the fastest.