如何将以下Objective-C代码转换为Swift代码?
#define MAX_SIZE 11 char buffer[MAX_SIZE]; time_t time = [[NSDate date] timeIntervalSince1970]; strftime(buffer, MAX_SIZE, "%-l:%M\u2008%p", localtime(&time)); NSString *dateString = [NSString stringWithUTF8String:buffer]; NSLog(@"dateString: %@", dateString); // dateString: 11:56 PM
我正在格式化date。
date
let maxSize: UInt = 11 var buffer: CChar[] = CChar[](count: Int(maxSize), repeatedValue: 0) var time: time_t = Int(NSDate().timeIntervalSince1970) var length = strftime(&buffer, maxSize, "%-l:%M\u2008%p", localtime(&time)) var dateString = NSString(bytes: buffer, length: Int(length), encoding: NSUTF8StringEncoding) NSLog("dateString: %@", dateString) // dateString: 11:56 PM