1

我们如何在 iPhone 中找到时间格式(无论是 12 小时还是 24 小时)模式?

在此处输入图像描述

4

1 回答 1

2

在上一个 SO 问题中检查Micheal Waterfall的这个答案Detect iPhone is display time in 12-Hour or 24-Hour Mode?

@implementation NSLocale (Misc)
- (BOOL)timeIs24HourFormat {
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateStyle:NSDateFormatterNoStyle];
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    NSString *dateString = [formatter stringFromDate:[NSDate date]];
    NSRange amRange = [dateString rangeOfString:[formatter AMSymbol]];
    NSRange pmRange = [dateString rangeOfString:[formatter PMSymbol]];
    BOOL is24Hour = amRange.location == NSNotFound && pmRange.location == NSNotFound;
    [formatter release];
    return is24Hour;
}
@end

希望这可以帮助

于 2011-09-16T06:21:17.937 回答