草庐IT

swift - 有没有办法确定一年在 Swift 中是否有闰月?

我看到了DateComponentshasanInstancePropertyisLeapMonth.它似乎是一个setter属性。我真正想知道的是一年,一个月是闰月。这在API中是否可行,或者我是否需要实现自己的算法才能这样做?非常感谢。 最佳答案 当设置为闰日时,您可以检查相关月份的第一天是否为有效日期:funcisLeap(month:Int,year:Int,era:Int,calendar:Calendar)->Bool{varcomponents=DateComponents()components.era=eracom