I am working on setting time whenever a slider moves, I followed this link Slider with real time in Label and got most of the stuff working, here is the code, which I am presently working on
//This code is to check whether the system settings is 24hr format or 12hr format
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setLocale:[NSLocale currentLocale]];
[formatter setDateStyle:NSDateFormatterNoStyle];
[formatter setTimeStyle:NSDateFormatterShortStyle];
NSString *dateString = [formatter stringFromDate:[NSDate date]];
NSRange amRange = [dateString rangeOfString:[formatter AMSymbol]];
NSRange pmRange = [dateString rangeOfString:[formatter PMSymbol]];
m_is24h = (amRange.location == NSNotFound && pmRange.location == NSNotFound);
Here is the slider code
UISlider *slider = (UISlider *)sender;
NSUInteger numberOfSlots = 24*2 - 1; //total number of 30mins slots
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"h:mm a"];
NSDate *zeroDate;
NSString *amString = [[formatter AMSymbol]uppercaseString];
NSString *timeString = [[[NSString stringWithFormat:@"12:00"]stringByAppendingString:@" "]stringByAppendingString:amString];
if(m_is24h)
{
zeroDate = [dateFormatter dateFromString:@"00:00"];
}
else
{
zeroDate = [dateFormatter dateFromString:timeString];
}
NSUInteger actualSlot = roundf(numberOfSlots*slider.value);
NSTimeInterval slotInterval = actualSlot * 30 * 60;
NSDate *slotDate = [NSDate dateWithTimeInterval:slotInterval sinceDate:zeroDate];
[dateFormatter setDateFormat:@"h:mm a"];
m_timeLabel.text = [[dateFormatter stringFromDate:slotDate]uppercaseString];
I tested this code with India region and everything works fine both for 24hr and 12hr format.Now when I change the region to Japan or Europe or any other region, the 24 hour format will not work when I move the slider, but If I change the format to 12hr from settings, it works, I am not understanding what mistake I am doing here.