Evgeniy S
Evgeniy S

Reputation: 1484

How to define which is (24/12) hour format on device?

How can i get information about which hours format prefer user? Is it any [application instace].prefferedTimeFormat or something like this?

enter image description here

Upvotes: 1

Views: 566

Answers (1)

Anupdas
Anupdas

Reputation: 10201

It's more like a hack can you try with this. If you use NSDateFormatterMediumSytle if user has turned on 24 hour format the dateFormat would be H:mm:ss if it's not turned on the format would be h:mm:ss a.

If you just want to set the format based on the user preferences just set the style of date and time to formatter. It will take care of the rest.

- (BOOL)is24HourFormat
{
    NSDateFormatter *dateFormatter = [NSDateFormatter new];
    [dateFormatter setTimeStyle:NSDateFormatterMediumStyle];
    return [dateFormatter.dateFormat isEqualToString:@"H:mm:ss"];
}

Upvotes: 5

Related Questions