Date
A specific point in time, independent of any calendar or time zone.
Declaration
struct DateMentioned in
Overview
A Date value encapsulates a single point in time, independent of any particular calendrical system or time zone. Date values represent a time interval relative to an absolute reference date.
The Date structure provides methods for comparing dates, calculating the time interval between two dates, and creating a new date from a time interval relative to another date. Use date values in conjunction with DateFormatter instances to create localized representations of dates and times and with Calendar instances to perform calendar arithmetic.
Date bridges to the NSDate class. You can use these interchangeably in code that interacts with Objective-C APIs.
Topics
Creating a Date
init()init(timeIntervalSinceNow:)init(timeInterval:since:)init(timeIntervalSinceReferenceDate:)init(timeIntervalSince1970:)
Retrieving the Current Date
Getting Temporal Boundaries
Comparing Dates
Getting Time Intervals
timeIntervalSince(_:)timeIntervalSinceNowtimeIntervalSinceReferenceDatetimeIntervalSince1970timeIntervalSinceReferenceDatetimeIntervalBetween1970AndReferenceDate
Adding or Subtracting a Time Interval
Formatting a Date
formatted()formatted(date:time:)formatted(_:)Date.FormatStyleDate.RelativeFormatStyleDate.IntervalFormatStyleISO8601Format(_:)Date.ISO8601FormatStyle
Describing Dates
Working with notification messages
Using Reference Types
Structures
Date.AnchoredRelativeFormatStyleDate.AttributedStyleDate.ComponentsFormatStyleDate.FormatStringDate.HTTPFormatStyleDate.ParseStrategyDate.VerbatimFormatStyle