开发者

How do I force a 24 hour format on all time values?

开发者 https://www.devze.com 2023-03-09 17:14 出处:网络
Is there a locale (or 开发者_JS百科any other code) that will force all my formating and my uiDatePicker to always be in English and 24 hour format?

Is there a locale (or 开发者_JS百科any other code) that will force all my formating and my uiDatePicker to always be in English and 24 hour format? I need this regardless of what the device settings are. many thanks...


For the UIDatePicker, there isn't a way within the SDK to make the component 24 hour (aside from the user selecting a locale in Settings.app which uses 24 hour times). What you'll need to do is roll your own using a UIPickerView and a custom data source, which is really quite simple, and then convert the values there into an NSDate using simple arithmetic.

For the time formatting, you can always choose what format you want to display NSDate objects by using a NSDateFormatter like the following:

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss Z"];
NSLog(@"the current 24hr date and time is %@", [formatter stringFromDate:[NSDate date]]);
[formatter release];

You can then wrap this into Utils class or what have you, and use it globally to format your dates into strings.

0

精彩评论

暂无评论...
验证码 换一张
取 消