本地化具有自定义字符串的 NSDateFormatter?

Localize NSDateFormatter which has a custom string?

我想本地化 NSDateFomatter,它在日期和时间之间有 'at' 个单词。知道怎么做吗?

//Create date formatter
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];

//Format
[dateFormatter setDateFormat:@"MMMM d 'at' h:mm a"];
return [dateFormatter stringFromDate:self];

你让事情变得更难了。

如果您对 dateStyletimeStyle 使用 NSDateFormatterLongStyle,那么 NSDateFormatter 会给您类似 "November 30, 2015 at 3:35:32 PM MST" 的结果。您可以使用不同的内置样式对其进行调整。例如,如果您将 timeStyle 设置为 NSDateFormatterShortStyle 但将 dateStyle 保留为 NSDateFormatterLongStyle,结果类似于 "November 30, 2015 at 3:36 PM"。 不要使用 dateFormat,让 NSDateFormatter 为您确定本地化

当您在美国时(例如),这会为您提供 "at",但 NSDateFormatter 会将其转换为适合当前语言环境的格式。因此,您将获得适合的内容,但语言环境通常表示时间和日期,但您无需告诉它使用单词 "at" 或尝试弄清楚如何翻译它。