I developing an application, in which i found a ridiculous problem in type casting, I am not able to type cast NSDate to NSString.
NSDate *selected =[datePicker date];
NSString *stringTypeCast = [[NSString alloc] initWithData:selected
encoding:NSUTF8StringEncoding];
From ,above snippet datePicker is an object of UIDatePickerController.
One method would be:
NSString *dateString = [NSString stringWithString:[selected description]]See the documentation.
Another would be:
NSString *dateString = [NSString stringWithFormat:@"%@", selected]See the documentation.
A more appropriate method would be:
This will automatically return the date in a string formatted to the user’s local date format. See the documentation.