2016-12-25 107 views

回答

1

您可以檢查,如果有問題該月的第一天,當設置爲飛躍,是一個有效的日期或不:

func isLeap(month: Int, year: Int, era: Int, calendar: Calendar) -> Bool { 
    var components = DateComponents() 
    components.era = era 
    components.year = year 
    components.month = month 
    components.day = 1 
    components.isLeapMonth = true 

    return components.isValidDate(in: calendar) 
} 

// The Chinese year that begins in 2017 
isLeap(month: 5, year: 34, era: 78, calendar: Calendar(identifier: .chinese)) // false 
isLeap(month: 6, year: 34, era: 78, calendar: Calendar(identifier: .chinese)) // true 

// The Chinese year that begins in 2020 
isLeap(month: 3, year: 37, era: 78, calendar: Calendar(identifier: .chinese)) // false 
isLeap(month: 4, year: 37, era: 78, calendar: Calendar(identifier: .chinese)) // true 

this list,有使用閏月幾日歷系統作爲日期更正機制。中國的日曆是我更熟悉的。您可以將其與list of leap months in the Chinese calendar

相關問題