本文介绍了转换的NSDate到字符串的strftime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将如何转换一个NSDate一个NSString的,由strftime符格式化?
How would I convert an NSDate to a NSString, formatted with strftime specifiers?
推荐答案
您可以使用的strftime。
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.
这篇关于转换的NSDate到字符串的strftime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!