是否可以在NSDateFormatter的格式字符串中添加自定义文本?

Amo*_*kar 31 objective-c nsdateformatter ios

假设我希望日期看起来像这样:

|1988|December|30|
Run Code Online (Sandbox Code Playgroud)

如何将这些添加到dateFormatter或者为此让格式如下:

30 in the month of December in the year of 1998
Run Code Online (Sandbox Code Playgroud)

现在是1988年,12月和30年,我想使用标准格式,但我希望我提出的文字也随之而来.

特别是在上述情况下,格式和管道只是在日期或月份的日期格式旁边,格式和管道之间没有空格.

只需设置格式就可以实现这一切吗?

Mar*_*n R 78

例如,您可以以日期格式插入任意文本(用单引号括起来).

NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
[fmt setDateFormat:@"dd' in the month of 'MMMM' in the year of 'yyyy"];
NSString *s = [fmt stringFromDate:[NSDate date]];
Run Code Online (Sandbox Code Playgroud)

结果:

09 in the month of July in the year of 2013


Jos*_*cis 6

迅捷版:

let dateFormatter = DateFormatter()
dateFormatter.dateFormat =  "EEEE' text here 'h:mm' and there 'a"
Run Code Online (Sandbox Code Playgroud)