first of all, I know this has been asked hundreds of times and I read probably 99 of all of the questions and answers. My issue is that I'm using times in my application and I have a setting, that lets the user override the actual system time-format. Means if the system uses 24h format, the user can still display the time in 12h format using that override setting.
However, it doesn't always work, here the cases:
1) System = 12h
Override off: displays 12h format
Override on (to 24h): displays 24h format
Override on (to 12h): displays 12h format
2) System = 24h
Override off: displays 24h format
Override on (to 24h): displays 24h format
Override on (to 12h): displays 24h format
It seems like in case 2) that I can't get it to display the 12h format :-/ And I've been trying all kinds off different things already. I'm fetching the setting (bool) and time from Core-Data. here is where I set my formatter in an if statement, which works that I verified using NSLog.
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
if (use24hFormat) {
// we have to use 24h time format
[formatter setDateFormat:@"HH:mm"];
NSLog(@"We have to use 24h-Format);
} else if (!use24hFormat) {
// we have to use 12h time format
[formatter setDateFormat:@"hh:mm a"];
NSLog(@"We have to use 12h-Format);
}
Any ideas?? Thanks guys
OUTPUT:
I believe you, I just ran your code (on iPhone with 24h format not simulator) and it does not work :-( Here is the OUTPUT
2014-06-27 21:02:39.565 Test[687:60b] We have to use 24h-Format
2014-06-27 21:02:39.572 Test[687:60b] timeString: 21:02
2014-06-27 21:02:39.574 Test[687:60b] We have to use 12h-Format
2014-06-27 21:02:39.576 Test[687:60b] timeString: 21:02
Then I ran it on simulator (also 24h format)
[3440:60b] We have to use 24h-Format
[3440:60b] timeString: 21:05
[3440:60b] We have to use 12h-Format
[3440:60b] timeString: 9:05 PM