开发者

Convert NSDate to String with strftime

How would I convert an NSDate to a NSString, formatted with st开发者_如何学Crftime specifiers?


you could use strftime.

NSDate *date = [NSDate date];
time_t time = [date timeIntervalSince1970];
struct tm timeStruct;
localtime_r(&time, &timeStruct);
char buffer[80];
strftime(buffer, 80, "%d.%m.%Y %H:%M:%S", &timeStruct);
NSString *dateStr = [NSString stringWithCString:buffer encoding:NSASCIIStringEncoding];

I hope it's correct.


You'll need an NSDateFormatter, using setDateFormat:. Here's the documentation.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜