Skip to content

Structure

DateComponents

iOS 8.0+ iPadOS 8.0+ Mac Catalyst 8.0+ macOS 10.9+ tvOS 9.0+ watchOS 2.0+
A date or time specified in terms of units (such as year, month, day, hour, minute) to be evaluated in a calendar system and time zone.
struct DateComponents

Overview

DateComponents encapsulates the components of a date in an extendable, structured manner.

It is used to specify a date by providing the temporal components that make up a date and time in a particular calendar: hour, minutes, seconds, day, month, year, and so on. It can also be used to specify a duration of time, for example, 5 hours and 16 minutes. A DateComponents is not required to define all the component fields.

When a new instance of DateComponents is created, the date components are set to nil.

Topics

Structures

  • struct HTTPFormatStyle
    Converts DateComponents into RFC 9110-compatible “HTTP date” String, and parses in the reverse direction. This parser does not do validation on the individual values of the components. An optional date can be created from the result using Calendar(identifier: .gregorian).date(from: ...). When formatting, missing or invalid fields are filled with default values: Sun, 01, Jan, 2000, 00:00:00, GMT. Note that missing fields may result in an invalid date or time. Other values in the DateComponents are ignored.
  • struct ISO8601FormatStyle
    Options for generating and parsing string representations of dates following the ISO 8601 standard.

Operators

Initializers

Instance Properties

Instance Methods

Default Implementations

Relationships

Conforms To

  • Foundation.ReferenceConvertible
  • Swift.Copyable
  • Swift.CustomDebugStringConvertible
  • Swift.CustomReflectable
  • Swift.CustomStringConvertible
  • Swift.Decodable
  • Swift.Encodable
  • Swift.Equatable
  • Swift.Escapable
  • Swift.Hashable
  • Swift.Sendable
  • Swift.SendableMetatype