Calendar.Component
An enumeration for the various components of a calendar date.
Declaration
enum ComponentOverview
You use one or more Calendar.Component values with the component(_:from:) or dateComponents(_:from:) methods to specify parts to extract from a given Date.
The following code listing shows how to use the year, month, and day components to get the corresponding units of the current Gregorian calendar date as a DateComponents instance.
let myCalendar = Calendar(identifier: .gregorian)
let ymd = myCalendar.dateComponents([.year, .month, .day], from: Date())Topics
Specifying Years and Months
Calendar.Component.eraCalendar.Component.yearCalendar.Component.yearForWeekOfYearCalendar.Component.quarterCalendar.Component.month
Specifying Weeks and Days
Calendar.Component.weekOfYearCalendar.Component.weekOfMonthCalendar.Component.weekdayCalendar.Component.weekdayOrdinalCalendar.Component.day
Specifying Hours, Minutes, and Seconds
Calendar.Component.hourCalendar.Component.minuteCalendar.Component.secondCalendar.Component.nanosecond