如何为NSDateFormatter设置区域设置?我试过下面的代码,但它不起作用。
- (NSString *)localizedStringWithFormat:(NSString *)format {
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:format];
NSCalendar *cal = [NSCalendar currentCalendar];
NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier: @"fr_FR"];
cal.locale = locale;
df.calendar = cal;
return [df stringFromDate:self];
}请让我知道如何使这件事成功。
谢谢。
发布于 2013-09-23 20:15:28
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
NSLocale *locale = [[NSLocale alloc]
initWithLocaleIdentifier:@"he"];
[dateFormatter setLocale:locale];发布于 2017-02-01 01:32:32
为了防止有人寻找Swift 3解决方案:
let dateFormatter = DateFormatter()
let frLocale = Locale(identifier: "fr")
dateFormatter.locale = frLocale发布于 2014-11-27 23:09:47
派对有点晚了,但我今天在斯威夫特做了这样的事:
let df = NSDateFormatter()
df.locale = NSLocale.currentLocale()
df.timeStyle = .MediumStyle
df.dateStyle = .MediumStyle
println("Date: \(df.stringFromDate(obj.dateSent!))")根据您的OS区域设置,输出应该如下所示(我在德国):
Date: 27.11.2014 12:30:39注意:只是发现更多的人偶然发现了这个问题,所以我想回答是不会有什么影响的。
https://stackoverflow.com/questions/18964747
复制相似问题