# Calendar

[frameworks](..) ⟩ [Foundation]() ⟩ Calendar

{% tabs %}
{% tab title="📗 參考" %}
* [ ] Sarun ⟩ [Getting the number of days between two dates in Swift](https://sarunw.com/posts/getting-number-of-days-between-two-dates/)&#x20;
* [ ] [Getting UIKit's UICalendarView from iOS 16 fully functioning in a SwiftUI app](http://chriswu.com/posts/swiftui/uicalendarview/)
{% endtab %}

{% tab title="🌀 Calendar" %}
```swift
import Foundation  // Calendar

extension Calendar {
    // Calendar.current.numberOfDays(between: date1, and: date2)
    public func numberOfDays(between date1: Date, and date2: Date) -> Int {
        let date1 = startOfDay(for: date1)
        let date2 = startOfDay(for: date2)
        let components = dateComponents([.day], from: date1, to: date2)
        return components.day!
    }
}
```
{% endtab %}

{% tab title="📘 手冊" %}
* [Calendar](https://developer.apple.com/documentation/foundation/calendar)
{% endtab %}

{% tab title="👥 相關" %}
* [datepicker](../../../../../swiftui/control/pickers/datepicker "mention")
* [date](date "mention")
{% endtab %}
{% endtabs %}
