如何检测设备的时间设置? [英] How detect time settings of device?

查看:199
本文介绍了如何检测设备的时间设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个闹钟应用程序.在我的应用程序中,问题是当设备日期和时间设置更改时,警报标签的文本也会更改.例如,如果将时间设置设置为24小时,则在我的标签文本中最后一次不显示am和pm,而将设置更改为12小时,则在标签文本中显示am和pm.如何检测日期和时间的设置是什么,以及如何对标签文本进行验证,而无论任何设置始终以上午和下午模式显示或以12小时设置显示?

I have an application in which i have made a alarm clock. In my application problem is that when device date and time settings changed then text of label of alarm also changed. For example if time settings is set as 24 hours then in my label 's text don't show am and pm in last while when change settings as 12 hours then in label's text show am and pm. How detect that what is settings of date and time and how apply validation on label's text that whatever settings always display in am and pm mode or show in 12 hours settings?

预先感谢...

推荐答案

Use can use this code:
NSDate *today = [NSDate date];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    // display in 12HR/24HR (i.e. 11:25PM or 23:25) format according to User Settings

    [dateFormatter setDateFormat:@"HH:mm"];
    NSString *currentTime = [dateFormatter stringFromDate:today];
    NSLog(@"%@",currentTime);
    [dateFormatter release];
Hear currentTime contains always 24 hour time format.

int hour =  [[[currentTime componentsSeparatedByString:@":"] objectAtIndex:0] intValue];
  if(hour > 12){
//show PM
}else{
//Show AM
}

这篇关于如何检测设备的时间设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆