iOS Swift converting calendar component int month to medium style string month

后端 未结 5 2103
后悔当初
后悔当初 2020-12-09 16:25

I want to display calendar in this format

\"visible

to the user. One option is to

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-09 17:03

    NSDateFormatter has monthSymbols, shortMonthSymbols and veryShortSymbols properties.

    So try this:

    let dateFormatter: NSDateFormatter = NSDateFormatter()
    
    let months = dateFormatter.shortMonthSymbols
    let monthSymbol = months[month-1] as! String // month - from your date components
    
    println(monthSymbol)
    

提交回复
热议问题