0

Hello I am trying to convert декабрь/12/1982 date into NSDate but it will return nil value. Following is my code.

NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
 [formatter setLocale:[NSLocale localeWithLocaleIdentifier:@"ru_RU"]];
 [formatter setDateFormat:@"MM/dd/yyyy"];

 NSDate *dateCreated = [formatter dateFromString:strSelectedDate];

My application has multi language support. Thanks in advance.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Diken Shah
  • 1,189
  • 9
  • 25
  • 1
    `MM` is for a 2-digit month number. Use `MMMM` for the month name. – rmaddy Aug 12 '15 at 06:51
  • @rmaddy, Thanks for your reply but output which i need is 01/12/2015 so that's why i use MM/dd/yyyy format. – Diken Shah Aug 12 '15 at 06:56
  • 1
    But your code is for converting the string to an `NSDate`. The format must match the string. If your then want to convert the `NSDate` to a new format, that's a 2nd step with a new format. – rmaddy Aug 12 '15 at 07:00
  • Your "strSelectedDate" should be in the same format as "MM/dd/yyyy". – Ardra Thambi Aug 12 '15 at 07:05

1 Answers1

2

this works:

NSString *temp = @"декабрь/12/1982";
NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
[formatter setLocale:[NSLocale localeWithLocaleIdentifier:@"ru_RU"]];
[formatter setDateFormat:@"LLLL/dd/yyyy"];
NSDate *dateCreated = [formatter dateFromString:temp];
NSLog(@"%@", dateCreated);

output is: 216:27582] 1982-12-11 23:00:00 +0000

Jiri Zachar
  • 487
  • 3
  • 8