How to determine the temporary settings of the device?

I have an application in which I made an alarm. In my application, the problem is that when the device’s date and time settings changed, the text of the alarm shortcut also changed. For example, if the time settings are set to 24 hours, then the last is not displayed in the label text and pm is the last time you change the settings as 12 hours, and then am and pm are displayed in the label text. How to determine what date and time settings are and how to apply label text validation, which settings are always displayed in am and pm mode or displayed in 12-hour settings?

Thanks for the success ...

+2
source share
2 answers
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
}
0
source

[dateFormatter setDateFormat:@"hh:mm a"];

[dateFormatter setDateFormat:@"HH:mm"];

NSString *currentTime = [dateFormatter stringFromDate:today];
NSLog(@"%@",currentTime);

NSLog 12- AM PM

-2

All Articles