24hr & uiDatePicker

2019-05-31 01:02发布

问题:

I need the time from my uiDatePicker to be in 24hr format, I understand you can't force this mode if the device is set to display AM/PM? If thats the case, how can I detect the device is in 24hr mode (or not) so I can add 12 to my PM times? Many thanks for any help...

回答1:

Wel you can, you need to set the local:

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;