NSDateFormatter “Month” in 3 letters instead of full word

后端 未结 7 1362
一生所求
一生所求 2021-02-01 03:00
    NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@\"dd-MM-YYYY HH:mm\"];        
    [formatter setTimeZone:[NSTimeZone syst         


        
7条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-01 03:23

    IF you get the two things in the wrong order, you don't get the expected output.

    [formatter setDateFormat:@"MMM"];
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    

    does NOT give the same results as:

    [formatter setDateStyle:NSDateFormatterMediumStyle];
    [formatter setDateFormat:@"MMM"];
    

    (The second of these two snippets is now happily handing out Sep Oct etc in my app)

提交回复
热议问题