2
我想要Convert NSDate to String with strftime,但%e
以空白爲單位先於一位數字。我如何防止這種情況?或者,如果我不能,那麼如果它是一個空間,刪除位置4處的字符的最佳方法是什麼?strftime在%e個位數之前沒有空白嗎?
// TODO: Don't precede %e with blank for single-digit days. @issue
char buffer[22]; // Sep 22, 2012 12:15 PM -- 21 chars + 1 for NUL terminator \0
time_t time = [message.sentDate timeIntervalSince1970] - [[NSTimeZone localTimeZone] secondsFromGMT];
strftime(buffer, 22, "%b %e, %Y %l:%M %p", localtime(&time));
messageSentDateLabel.text = [NSString stringWithCString:buffer encoding:NSUTF8StringEncoding];
不錯。謝謝!我也將%l更改爲%-l。 – ma11hew28