tags:

views:

663

answers:

2

I want to convert NSDate to NSString? How 's that possible?

I tried this , but it didn't work (generating Exception) :

NSString *dateToString=[[NSString alloc] initWithFormat:(NSString *)dateObj];

Thanks in advance...

+3  A: 

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.

m5h
Thanks It works ...
Nic
A: 

http://cocoawithlove.com/2009/05/simple-methods-for-date-formatting-and.html

There is a detailed list of parameters.

Sijo