开发者

How to convert NSDate to NSString?

开发者 https://www.devze.com 2022-12-11 22:19 出处:网络
I want to convert NSDate to NSString? How\'s that possible? I tried this, but it didn\'t work (i开发者_如何学编程t is generating Exception) :

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

I tried this, but it didn't work (i开发者_如何学编程t is generating Exception) :

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

Thanks in advance.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消