我想在我的iphone应用中使用 DateFormatter 。用于设置 - >常规 - >日期和时间。
先谢谢。
答案 0 :(得分:1)
使用默认本地(这是用户在设置 - >常规 - >日期&时间中选择的内容)Apple提供了一种快速方法localizedStringFromDate:dateStyle:timeStyle:
仅举例说明使用日期:
NSString *datePresentaion =
[NSDateFormatter localizedStringFromDate:someDate dateStyle:NSDateFormatterLongStyle timeStyle:NSDateFormatterNoStyle];
如果您要创建NSDateFormatter
的实例,则需要告诉用户本地的实例:
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.locale = [NSLocale currentLocale];