Reputation: 343
i want to disable 24 - clock format in UIDatePicker , My requirement is to show only AM/PM format date picker. If user enable the 24-hour Time in the phone settings. my date Picker is Showing 24 - hour format, i want force it to show 12 - hour format. Please suggest me.
Thanks,
Upvotes: 0
Views: 2943
Reputation: 721
For 24 hr format try...
NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"NL"];
[self.datePicker setLocale:locale];
Upvotes: 1
Reputation: 933
Date format depends of your device locale settings.
Although it's not recommended in most cases, you can override locale settings:
For example this gives you 24h format:
self.datePicker.locale = [NSLocale localeWithLocaleIdentifier:@"en_GB"];
and this 12h format with PM/AM
self.datePicker.locale = [NSLocale localeWithLocaleIdentifier:@"en_US"];
Upvotes: 7
Reputation: 4917
We can Customise only current date will be in 24hrs format if user set means as per iOS device settings .. Otherwise we can set like this
NSDate *currDate = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
NSString *dateString = [dateFormatter stringFromDate:currDate];
_todayDateLbl.text=dateString;
#pragma get current time
dateFormatter.dateFormat = @"hh:mm a";
[dateFormatter setTimeZone:[NSTimeZone systemTimeZone]];
NSLog(@"The Current Time is %@",[dateFormatter stringFromDate:currDate]);
Upvotes: 2
Reputation: 1611
You just cannot set the 12/24 format.
It depends on user's setting on their iOS device.
Upvotes: 1