2016-05-30 140 views
0

我試圖讓當前的月份和葡萄牙語書寫得一個月,但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 
+2

Tudo bem。它按預期工作。考慮模擬器的默認語言環境是「en_US」。 – vadian

回答

2

你可以試試這個

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"