8

I make search and up to now I see that UIDatePicker is working with localization of the device.

I have app which has internal lozalization. I need to change month's text dependantly of my internal localization. As I read it appears that this is not possible - I have to make my own custom picker.

Is there a way to achieve that without custom Dat picker?

new2ios
  • 1,350
  • 2
  • 25
  • 56

6 Answers6

25

Use locale property of UIDatePicker. I can't see any signs that the property is deprecated.

This code will localize picker to Japanese.

[datePicker setLocale: [NSLocale localeWithLocaleIdentifier:@"ja"]];

Replace "ja" with any language code you need.

Andrey Kuznetsov
  • 843
  • 1
  • 18
  • 29
  • 10x, @Andrey Kuznetsov works great! I also think to use that, but when I search over the web I see many different solutions, so I get confused. – new2ios Jun 01 '15 at 10:49
  • See [my answer](http://stackoverflow.com/a/35499631/3340702) for the **swift** version. – lifeisfoo Feb 19 '16 at 07:24
  • But Time displaying 12 Hrs format instead of 24 Hrs. – Kirti Nikam Jul 20 '18 at 13:47
  • 1
    12/24 hour format depends on locale setup and could be changed from default by user in system settings. So there is no 100% reliable way to do this. See question https://stackoverflow.com/q/11151187/ for more information on that – Andrey Kuznetsov Jul 21 '18 at 04:37
12

With Swift

let datePicker:UIDatePicker = UIDatePicker()
datePicker.locale = NSLocale.init(localeIdentifier: "it_IT")

Replace the it_IT string (for Italian-speaking people) with your locale identifier. Common cases for english are:

  • en for generic English-speaking people
  • en_US for English-speaking residents of the United States
  • en_GB for English-language speakers in the United Kingdom

For more information about the locale identifier see the Locale IDs section of "Internationalization and Localization Guide" by Apple

If you're interested in getting the current locale see How do I get current application locale?

Community
  • 1
  • 1
lifeisfoo
  • 15,478
  • 6
  • 74
  • 115
6

Swift 3.0 and New

This code will locale picker to Chinese. Here datePicker is object of UIDatePicker.

datePicker.locale = Locale.init(localeIdentifier: "zh-Hans")
  • Use "en" instead of "zh-Hans" for English .
  • Use "az-Arab" instead of "zh-Hans" for Arabic.
  • Use "uz-Latn" instead of "zh-Hans" for Latin.

for more : click here

Harshil Kotecha
  • 2,846
  • 4
  • 27
  • 41
1

The UIDatePicker, by default, uses whatever [NSLocale currentLocale] dictates.

The locale property on UIDatePicker was deprecated in iOS 5, but you can try this:

NSLocale *loc = [[NSLocale alloc] initWithLocaleIdentifier:@"..."];
NSCalendar *cal = [NSCalendar currentCalendar];
[cal setLocale:loc];
[myDatePicker setCalendar:cal];
arturdev
  • 10,884
  • 2
  • 39
  • 67
  • 1
    I try this @arturdev. It does not working. My `UIDatePickerView` is in `Storyboard`. When I put this for a specific language - it not affects App when it runs - the default is English. I can set `Locale` in designer - it is ok, but I don't know how to change it during runtime. When I change language in the App I need also localize. – new2ios Jun 01 '15 at 09:22
0

UIDatePicker localize is dependent on the "Region Format" setting of device.

Settings > General > International > Region Format

Santu C
  • 2,644
  • 2
  • 12
  • 20
0

I think it is not possible with selecting UIDatepicker control may be you can do it with UIPickerview. please check this link. (you can do it like this way) UI appearance Datepicker
or Custom Color of Datepicker I hope it is helpfull to you.

Community
  • 1
  • 1
Badal Shah
  • 7,541
  • 2
  • 30
  • 65