I want to convert NSDate to NSString? How's that possible?
I tried this, but it didn't work (it is generating Exception) :
NSString *dateToString=[[NSString alloc] initWithFormat:(NSString *)dateObj];
Thanks in advance.
dateFormat = @"MMMM dd, yyyy"; NSString* dateString = [formatter stringFromDate:date]; Convert a String to a Date: NSDateFormatter* formatter = [[NSDateFormatter alloc]init];
You can achieve this with the NSDateFormatter
.
Example:
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
NSString *string = [dateFormatter stringFromDate:date];
[dateFormatter release];
For more ways of controlling the format of the string, see the reference documentation for NSDateFormatter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With