24小时/ 12小时时钟问题

And*_*rew 0 iphone cocoa-touch objective-c

在我的应用程序中它花费时间,但我注意到在设备上的设置中,如果用户将其设置为24小时时钟,它按预期工作,其中当前日期的HH返回,例如14.但如果他们有它设置为12小时制,它返回2.是否有办法解决这个问题?

Ned*_*Ned 6

使用此代码,我总是得到24小时时钟值.

NSCalendar *cal = [NSCalendar currentCalendar];
NSDate* now = [NSDate date]; 
int hours = [[cal components:NSHourCalendarUnit fromDate:now] hour];
Run Code Online (Sandbox Code Playgroud)