相关疑难解决方法(0)

如何确定iPhone是否设置为12小时或24小时时间显示?

我以为我最近在SO上看到了回答这个问题,但现在我找不到了.这是我现在使用的代码,用于确定设置是否为24小时时间显示.它适用于我在美国,但我不知道它是否适用于所有语言环境.这是否足够或是否有更好的方法来找出当前的设置?

+(BOOL) use24HourClock
{
    BOOL using24HourClock = NO;

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];    
    [dateFormatter setLocale: [NSLocale currentLocale]];    
    [dateFormatter setDateStyle:kCFDateFormatterNoStyle];
    [dateFormatter setTimeStyle:kCFDateFormatterShortStyle];    
    // get date/time (1Jan2001 0000UTC)
    NSDate* midnight = [[NSDate alloc] initWithTimeIntervalSinceReferenceDate:0];   
    NSString* dateString = [dateFormatter stringFromDate: midnight];
    // dateString will either be "15:00" or "16:00" (depending on DST) or
    // it will be "4:00 PM" or "3:00 PM" (depending on DST)
    using24HourClock = ([dateString length] == 5);
    [midnight release];
    [dateFormatter release];    

    return using24HourClock;
}
Run Code Online (Sandbox Code Playgroud)

iphone datetime localization

41
推荐指数
3
解决办法
1万
查看次数

检测时间格式是否为12小时或24小时格式

有没有办法检测应用程序的当前设备是否使用12h我们的24h格式,以便我可以使用一个NSDateFormatter 12h和一个24h取决于用户语言/ loaction设置?就像UIDatePicker检测并显示AM/PM选择器(如果它是12h格式).

cocoa-touch objective-c nstimezone ios

39
推荐指数
3
解决办法
2万
查看次数