I have a date picker in my app. The phone is set to Bangladesh local settings. When I select a date from datepicker is always returns the date in Bengali. It return a date in local format.
Like, it returns ০৬/১১/২০১৪
but I want it to be 06/11/2014.
I've tried converting it by date formatter. This is what I tried:
NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
[formatter setLocale:[NSLocale currentLocale]];
NSDate* date = [formatter dateFromString: self.birthDate.text];
NSDateFormatter *formater = [[NSDateFormatter alloc] init];
[formater setLocale:[NSLocale localeWithLocaleIdentifier:@"en_US"]];
[formater setDateFormat:@"dd/MM/yyyy"];
NSLog(@"%@",[formater stringFromDate:date]);
The output is null.
You are incorrect in your assumption when you say...
UIDatePicker
returns anNSDate
object.NSDate
has no formatting at all. It has no language, it is purely a point in time.When you do this...
The system will render that point in time into a string and then print it. It is the rendering into a string that contains the format.
I'm guessing what you are doing is this...
UIDatePicker
.UITextField
in Bengali. (or label, or text view or something)What you should be doing is just saving the date that comes from the date picker.
Put it into a property or something.
In your above code I think the bit that is failing is actually the first bit...
Because you're not giving it a format it will fail. But this is the wrong way to go about it anyway.
You should have something like this...