I have a textfield where user enters "MM/dd/yyyy" format of date.
I want to convert this into date. If user enters date correctly, it is working fine. If by chance user enters date in "dd/MM/yyyy", it is not returning date properly. I know that in the following code we are using "setDateFormat". My question is that what will be NSDate* dateOfBirth holding if user enters string in wrong format? Why is it not throwing any error or exception?
I want to convert this into date. If user enters date correctly, it is working fine. If by chance user enters date in "dd/MM/yyyy", it is not returning date properly. I know that in the following code we are using "setDateFormat". My question is that what will be NSDate* dateOfBirth holding if user enters string in wrong format? Why is it not throwing any error or exception?
Code:
NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"MM/dd/yyyy"];
NSDate* dateOfBirth = [dateFormatter dateFromString:[dob text]];