Is it possible to add custom text in NSDateFormatter's format string?

后端 未结 3 967
醉酒成梦
醉酒成梦 2020-12-06 03:44

Suppose I want the date to look like this:

|1988|December|30|

How can add these to the dateFormatter or for that matter let the format be s

3条回答
  •  被撕碎了的回忆
    2020-12-06 04:37

    You can insert arbitrary text (enclosed in single quotes) in the date format, for example.

    NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
    [fmt setDateFormat:@"dd' in the month of 'MMMM' in the year of 'yyyy"];
    NSString *s = [fmt stringFromDate:[NSDate date]];
    

    Result:

    09 in the month of July in the year of 2013
    

提交回复
热议问题