Friday May 31, 2013 12:00 pm
| 符號 | 含義 | 範例 |
|---|---|---|
cccc | 星期完整名稱 | Friday |
MMMM | 月份完整名稱 | May |
dd | 兩位數日期 | 31 |
yyyy | 四位數年份 | 2013 |
hh | 12小時制時 | 12 |
mm | 分鐘 | 00 |
a | AM/PM | pm |
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"cccc MMMM dd, yyyy hh:mm a"];
formatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]; // 關鍵:固定英文輸出
NSString *result = [formatter stringFromDate:[NSDate date]];
// 輸出: "Friday May 31, 2013 12:00 PM"
locale = en_US_POSIX,否則受用戶地區設定影響(如中文環境會顯示「星期五 五月...」)。