2011-06-01 61 views
1

我需要从我的uiDatePicker的时间为24小时格式,我知道如果设备设置为显示AM/PM,您不能强制此模式? 如果是这样的话,我怎么能检测到设备是在24小时模式(或不),所以我可以添加12到我的下午时间? 非常感谢您的帮助......24小时和uiDatePicker

回答

2

WEL你可以,你需要设置本地:

NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; 
[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss Z"]; 
NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"NL"]; 
NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:@"UTC"]; 
[formatter setTimeZone:timeZone]; 
[formatter setLocale:locale]; 
[locale release], locale = nil; 
+0

谢谢rckoenes,是“NL”显著?我们是否暂时使用它来强制24小时模式? – mtompson 2011-06-01 08:03:31

+0

不,你可以使用英国,它只是我住荷兰。格式化程序本地化非常重要,那么您可以使用任何数据格式。 – rckoenes 2011-06-01 08:05:24

+0

这只是荷兰语区域。您可以根据需要更改它,或者检查NSLocale类的引用,以便能够输出设备上所有可用语言环境的列表。 – Luke 2011-06-01 08:05:59