Iphone 24小时/12小时时钟问题

Iphone 24小时/12小时时钟问题,iphone,objective-c,cocoa-touch,Iphone,Objective C,Cocoa Touch,在我的应用程序中,这需要时间,但我注意到,在设备的设置中,如果用户将其设置为24小时时钟,则在当前日期的HH返回的位置(例如14)会按预期工作。但如果他们将其设置为12小时时钟,则返回为2。有没有办法解决这个问题?使用这个代码,我总是能得到24小时的时钟值 NSCalendar *cal = [NSCalendar currentCalendar]; NSDate* now = [NSDate date]; int hours = [[cal components:NSHourCalendar

在我的应用程序中,这需要时间,但我注意到,在设备的设置中,如果用户将其设置为24小时时钟,则在当前日期的HH返回的位置(例如14)会按预期工作。但如果他们将其设置为12小时时钟,则返回为2。有没有办法解决这个问题?

使用这个代码,我总是能得到24小时的时钟值

NSCalendar *cal = [NSCalendar currentCalendar];
NSDate* now = [NSDate date]; 
int hours = [[cal components:NSHourCalendarUnit fromDate:now] hour];

使用这个代码,我总是得到24小时的时钟值

NSCalendar *cal = [NSCalendar currentCalendar];
NSDate* now = [NSDate date]; 
int hours = [[cal components:NSHourCalendarUnit fromDate:now] hour];

我没有真正理解这个问题。14应该是12小时时钟中的2。您可能还想了解如何处理NSDateFormatter和24小时时间设置的问题。我真的不理解这个问题。14应该在12小时时钟中显示为2。您可能还想了解如何使用NSDateFormatter和24小时时间设置处理问题。