首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >iOS:如果区域设置合适,是否以24小时格式显示时间?

iOS:如果区域设置合适,是否以24小时格式显示时间?
EN

Stack Overflow用户
提问于 2011-11-23 07:18:31
回答 2查看 2.9K关注 0票数 5

我的iOS应用程序将显示当前时间。如何确定用户的区域设置首选12小时制还是24小时制时间格式?

EN

回答 2

Stack Overflow用户

发布于 2011-11-23 08:11:03

请参见NSDateFormatter类http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSDateFormatter_Class/Reference/Reference.html

类似于:

代码语言:javascript
复制
NSDate *date = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];

[dateFormatter setDateStyle:NSDateFormatterNoStyle];
[dateFormatter setTimeStyle:NSDateFormatterMediumStyle];
[dateFormatter setLocale:[NSLocale currentLocale]];

NSString *dateString = [dateFormatter stringFromDate:date];
票数 1
EN

Stack Overflow用户

发布于 2011-11-23 08:25:08

在向用户显示数据时,通常不需要确定用户的区域设置是什么。如果您使用相关的NSFormatter (NSNumberFormatter表示数字,NSDateFormatter表示日期和时间,在本例中与您相关),那么您将自动获得适合用户区域设置的输出……即苹果所谓的"localized representation of the object

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8235299

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档