如何将CFAbsoluteTime
结构转换为YYYY-MM-DD HH:MM:SS
格式?
答案 0 :(得分:4)
你可以使用这段代码(纯CoreFoundation):
CFAbsoluteTime cfTime = CFAbsoluteTimeGetCurrent();
CFDateRef cfDate = CFDateCreate(kCFAllocatorDefault, cfTime);
CFDateFormatterRef dateFormatter = CFDateFormatterCreate(kCFAllocatorDefault, CFLocaleCopyCurrent(), kCFDateFormatterFullStyle, kCFDateFormatterFullStyle);
CFStringRef newString = CFDateFormatterCreateStringWithDate(kCFAllocatorDefault, dateFormatter, cfDate);
CFRelease(dateFormatter);
CFRelease(cfDate);
kCFDateFormatterFullStyle表征格式。选择一个更适合你的方式:)