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.
精彩评论