我有以下内容:
NSDateFormatter* df = [[NSDateFormatter alloc]init];
[df setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZ"];
NSDate* date = [df dateFromString:[sDate stringByReplacingOccurrencesOfString:@"Z" withString:@"-0000"]];
[df release];
我希望输出字符串是“9/20/10”
我该怎么做?
最佳答案
你可以这样做:
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setFormatterBehavior:NSDateFormatterBehavior10_4];
[formatter setDateStyle:NSDateFormatterShortStyle];
[formatter setTimeStyle:NSDateFormatterNoStyle];
NSString *result = [formatter stringFromDate:[NSDate date]];
这将在用户设置中显示(但以类似的方式),所以对我来说结果将是 2010 年 7 月 28 日
关于iphone - 将 NSDate 转换为 NSString,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3356108/