假设我希望日期看起来像这样:
|1988|December|30|
如何将这些添加到 dateFormatter 或就此而言让格式像这样:
30 in the month of December in the year of 1998
现在是 1988 年、12 月和 30 日,我想使用标准格式,但我希望我放入的文本也能伴随它们。
特别是在上述情况下,格式和管道仅与日期或月份的日期格式相邻,格式和管道之间没有空格。
仅通过设置格式就可以做到这一点吗?
最佳答案
例如,您可以在日期格式中插入任意文本(用单引号引起来)。
NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
[fmt setDateFormat:@"dd' in the month of 'MMMM' in the year of 'yyyy"];
NSString *s = [fmt stringFromDate:[NSDate date]];
结果:
09 in the month of July in the year of 2013
关于ios - 是否可以在 NSDateFormatter 的格式字符串中添加自定义文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17542564/