用葡萄牙语获得月份

时间:2016-05-30 16:03:16

标签: swift

我正在努力获得当前月份并用葡萄牙语写作,但NSLocale pt_br无法正常工作......其英文版本:

    let date = NSDate()
    let calendar = NSCalendar.currentCalendar()
    calendar.locale = NSLocale(localeIdentifier: "pt_BR")
    let components = calendar.components([.Month , .Year], fromDate: date)

    let dateFormatter: NSDateFormatter = NSDateFormatter()
    dateFormatter.locale = NSLocale(localeIdentifier: "pt_BR")
    let months = dateFormatter.shortMonthSymbols

    let year =  components.year
    let month = components.month
    let monthSymbol = months[month-1] // month - from your date components

1 个答案:

答案 0 :(得分:3)

你可以试试这个

let date = NSDate()

let dateFormatter = NSDateFormatter()
dateFormatter.locale = NSLocale(localeIdentifier: "pt_BR")
dateFormatter.dateFormat = "MMMM"  // use "MMM" for short names

let monthString = dateFormatter.stringFromDate(date) // "maio"