NSDateFormatter “Month” in 3 letters instead of full word

后端 未结 7 1350
一生所求
一生所求 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:41

    This is a stripped down solution that works with Swift 4 in producing a 3 letter month output:

    let dateFormatter = DateFormatter()
    dateFormatter.dateFormat = "dd MMM YYYY, HH:mm:ss"
    

    And to verify:

    print(dateFormatter.string(from: Date())) // 20 Mar 2018, 23:41:40
    

    As previously noted, MMM is the correct syntax for getting the desired month output.

    0 讨论(0)
提交回复
热议问题