gpt4 book ai didi

iphone - 检测iPhone是否以12小时或24小时模式显示时间?

转载 作者:行者123 更新时间:2023-12-03 18:30:24 25 4
gpt4 key购买 nike

如何检测 iPhone 是以 12 小时还是 24 小时模式显示时间?

我当前监视当前区域的更改,但这并不是影响时间显示方式的唯一设置。日期和时间设置中的 24 小时切换会覆盖当前区域设置。

有什么办法可以检测到这个 12/14 小时设置吗?

最佳答案

我已经找到了一种确定这一点的好方法,方法是在 NSLocale 类别中添加一个小函数。它看起来相当准确,并且在多个区域进行测试时没有发现任何问题。

@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

关于iphone - 检测iPhone是否以12小时或24小时模式显示时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1972108/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com