StructureFoundation5.9.0
DateComponents
DateComponents
encapsulates the components of a date in an extendable, structured manner.
struct DateComponents
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
.
Citizens in Foundation
Conformances
protocol CustomDebugStringConvertible
A type with a customized textual representation suitable for debugging purposes.
protocol CustomReflectable
A type that explicitly supplies its own mirror.
protocol CustomStringConvertible
A type with a customized textual representation.
protocol Decodable
A type that can decode itself from an external representation.
protocol Encodable
A type that can encode itself to an external representation.
protocol Equatable
A type that can be compared for value equality.
protocol Hashable
A type that can be hashed into a
Hasher
to produce an integer hash value.protocol ReferenceConvertible
Decorates types which are backed by a Foundation reference type.
Members
init(calendar: Calendar?, timeZone: TimeZone?, era: Int?, year: Int?, month: Int?, day: Int?, hour: Int?, minute: Int?, second: Int?, nanosecond: Int?, weekday: Int?, weekdayOrdinal: Int?, quarter: Int?, weekOfMonth: Int?, weekOfYear: Int?, yearForWeekOfYear: Int?
) Initialize a
DateComponents
, optionally specifying values for its fields.init(from: Decoder
) throws var calendar: Calendar?
The
Calendar
used to interpret the other values in this structure.var customMirror: Mirror
var date: Date?
Returns a
Date
calculated from the current components using thecalendar
property.var day: Int?
A day or count of days.
var debugDescription: String
var description: String
var era: Int?
An era or count of eras.
var hour: Int?
An hour or count of hours.
var isLeapMonth: Bool?
Set to true if these components represent a leap month.
var isValidDate: Bool
Returns true if the combination of properties which have been set in the receiver is a date which exists in the
calendar
property.var minute: Int?
A minute or count of minutes.
var month: Int?
A month or count of months.
var nanosecond: Int?
A nanosecond or count of nanoseconds.
var quarter: Int?
A quarter or count of quarters.
var second: Int?
A second or count of seconds.
var timeZone: TimeZone?
A time zone.
var weekOfMonth: Int?
A week of the month or a count of weeks of the month.
var weekOfYear: Int?
A week of the year or count of the weeks of the year.
var weekday: Int?
A weekday or count of weekdays.
var weekdayOrdinal: Int?
A weekday ordinal or count of weekday ordinals. Weekday ordinal units represent the position of the weekday within the next larger calendar unit, such as the month. For example, 2 is the weekday ordinal unit for the second Friday of the month.///
var year: Int?
A year or count of years.
var yearForWeekOfYear: Int?
The ISO 8601 week-numbering year of the receiver.
static func == (DateComponents, DateComponents
) -> Bool func encode(to: Encoder
) throws func hash(into: inout Hasher
) func isValidDate(in: Calendar
) -> Bool Returns true if the combination of properties which have been set in the receiver is a date which exists in the specified
Calendar
.func setValue(Int
?, for: Calendar.Component) Set the value of one of the properties, using an enumeration value instead of a property name.
func value(for: Calendar.Component
) -> Int? Returns the value of one of the properties, using an enumeration value instead of a property name.
typealias ReferenceType