Show Time in 12 and 24 hour format in UIDatepicker on the basis of app settings not on device Settings

前端 未结 10 1157
夕颜
夕颜 2020-12-01 07:55

My problem is there is a switch in my app which toggles for 12 hour and 24 hour time format.I am displaying my labels time according to that, but the UIDatePicker

10条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-01 08:36

    If I understand you correctly you need to find out whether the device settings is has 12 hrs or 24 hrs format. Sorry if this solution is a little late.

     -(BOOL)returnDefaultDateFormat
       {
           NSString *formatStringForHours = [NSDateFormatter dateFormatFromTemplate:@"j"     options:0 locale:[NSLocale currentLocale]];
           NSRange containsA = [formatStringForHours rangeOfString:@"a"];
           BOOL hasAMPM = containsA.location != NSNotFound;
           return hasAMPM;
    }
    

提交回复
热议问题