开发者

Convert NSDate to String with strftime

开发者 https://www.devze.com 2023-02-11 04:28 出处:网络
How would I convert an NSDate to a NSString, formatted with st开发者_如何学Crftime specifiers?you could use 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

精彩评论

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