将2013年05月05日转换为2013-05-05

#define NSLog(FORMAT, ...) printf("%s ", [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String])

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {

    @autoreleasepool {

        //将2013年05月05日转换为2013-05-05

        NSMutableString *str=@"2013年05月05日";

        NSLog(@"原字符串为:%@",str);

        

        NSString *str1=[str stringByReplacingOccurrencesOfString:@"年" withString:@"-"];

        NSString *str2=[str1 stringByReplacingOccurrencesOfString:@"月" withString:@"-"];

        NSString *str3=[str2 stringByReplacingOccurrencesOfString:@"日" withString:@""];

        

        NSLog(@"修改以后为:%@",str3);

    }

    return 0;

}

原文地址:https://www.cnblogs.com/shaowenlong/p/5116733.html