我的iOS应用程序将显示当前时间。如何确定用户的区域设置首选12小时制还是24小时制时间格式?
发布于 2011-11-23 08:11:03
请参见NSDateFormatter类http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSDateFormatter_Class/Reference/Reference.html
类似于:
NSDate *date = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateStyle:NSDateFormatterNoStyle];
[dateFormatter setTimeStyle:NSDateFormatterMediumStyle];
[dateFormatter setLocale:[NSLocale currentLocale]];
NSString *dateString = [dateFormatter stringFromDate:date];发布于 2011-11-23 08:25:08
在向用户显示数据时,通常不需要确定用户的区域设置是什么。如果您使用相关的NSFormatter (NSNumberFormatter表示数字,NSDateFormatter表示日期和时间,在本例中与您相关),那么您将自动获得适合用户区域设置的输出……即苹果所谓的"localized representation of the object“
https://stackoverflow.com/questions/8235299
复制相似问题