Why does this code return 12:00:05 am (not 00:00:05)? (System time format is set to 12-Hour.)
How can I get what I want without hardcoding new locale? (because users' prefs should stay users' prefs and there is no guarantee/control that locale will provide exact time format for me.
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"HH:mm:ss"];
NSDate *date = [[NSDate alloc] init];
NSString *currentDateAndTime = [dateFormatter stringFromDate:date];
NSLog(@"%@", currentDateAndTime);
People say that NSDate stores seconds and does not store format. So it must depend on format set by NSDateFormatter, not on system time format, but it does not. Why?
UPD: I've got solution, but still do not have an answer Why? — any ideas?
Specified current locale and got what I need:
[dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:[[NSLocale currentLocale] localeIdentifier]]];
UPD 2: My KK solution does not work
When time crosses noon mark it returns 00:00:00. Like it's crossed midnight
Solved by setting locale to en_GB
Don't know how it works, so not sure if it's going to work properly in the future. As for me it would be better to know if time set to 24 hour format. Or to see the locale's insides