Contents

Calendar.Component

An enumeration for the various components of a calendar date.

Declaration

enum Component

Overview

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

Specifying Weeks and Days

Specifying Hours, Minutes, and Seconds

Specifying Calendars and Time Zones

Enumeration Cases

See Also

Extracting Components