2
私はそれを参照してくださいDateComponents has an Instance Property isLeapMonth。これはセッタープロパティのようです。私が本当に知りたいのは1年、1ヶ月はうるう年です。これはAPIで可能ですか、そうするために独自のアルゴリズムを実装する必要がありますか?事前に多くの感謝。Swiftに1年の閏月があるかどうかを判断する方法はありますか?
私はそれを参照してくださいDateComponents has an Instance Property isLeapMonth。これはセッタープロパティのようです。私が本当に知りたいのは1年、1ヶ月はうるう年です。これはAPIで可能ですか、そうするために独自のアルゴリズムを実装する必要がありますか?事前に多くの感謝。Swiftに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
との相互参照ができます