2016-12-25 73 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

相关问题