2

I want to set date format in date picker for region "es_us"(Spanish-UnitedStates) in my app .For this i have set locale to date picker "es-US" . When Date picker appears it shows date picker in format "dd/MM/yyyy" but actually date format for locale "es-US" is "MM/dd/yyyy". how can i set format to dd/MM/yyyy in date picker ? below is my code what i have written .

   UIDatePicker *datePicker = [[UIDatePicker alloc]init];
    datePicker.datePickerMode = UIDatePickerModeDate;
    datePicker.maximumDate = [NSDate date];
    datePicker.hidden = YES;
    datePicker.date = [[NSDate date] dateByAddingTimeInterval:-2629743.83*12*25];
    datePicker.locale =  [[NSLocale alloc] initWithLocaleIdentifier:@"es_US"];

Please help me.

Thanks in advance

rmaddy
  • 314,917
  • 42
  • 532
  • 579
VDPATEL
  • 416
  • 3
  • 18

2 Answers2

0

There may be issue of NSlocale try this one

NSArray* languages = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"];
NSString *language = [[NSLocale currentLocale] displayNameForKey:NSLocaleIdentifier value:     [languages objectAtIndex:0]];
[formatter setLocale:[NSLocale localeWithLocaleIdentifier:language]];

This may help you

Arpit
  • 722
  • 5
  • 15
  • @@arpit:Thanks for suggestion . I have tried above code ,but it sets my date-format but now date picker is in English ,i want it in Spanish.:( – VDPATEL Apr 16 '14 at 09:24
0

In Apple's documentation they specified that in UIDatePickerModeDate. The DatePicker displays months, days of the month, and years. The exact order of these items depends on the locale setting. An example of this mode is [ November | 15 | 2007 ]. But In device it display as DD/MM/YYYY. See UIDatePicker for more info.

Although The locale property for UIDatePicker was deprecated from iOS 5.

or you could create your own UIPickerView with the values you want.

you can check this answer too..

https://stackoverflow.com/a/8944352/1865424

and your 2nd issue regarding changing language of UIDatePicker ..

The locale property (and all other country specific format properties for that matter) defaults to the value returned by currentLocale, which in turns depends on the iphone's country settings, not the language settings. You need to set the appropriate country in the iphone general settings.

Courtesy:- https://stackoverflow.com/a/2265984/1865424

Community
  • 1
  • 1
Kundan
  • 3,084
  • 2
  • 28
  • 65