0Pricing
Swift Academy · Lesson

Calendar and DateComponents

Do date arithmetic across calendars.

Calendar and DateComponents

A Calendar interprets a Date into human units like year, month, and day. DateComponents holds those broken-out values.

The Current Calendar

Calendar.current reflects the user's settings. It is the gateway between raw Date instants and named fields.

import Foundation

let cal = Calendar.current
print("Calendar identifier: \(cal.identifier)")

All lessons in this course

  1. The Date Type and Time Intervals
  2. Calendar and DateComponents
  3. Formatting Dates
  4. Time Zones and Locales
← Back to Swift Academy