Date
struct Date : ReferenceConvertible, Comparable, Equatable
-
The number of whole 7-day periods until the date represented by the receiver. If the receiver is in the past, the value will be negative.
Declaration
Swift
public var weeksUntil: Int -
The number of whole 24-hour periods until the date represented by the receiver. If the receiver is in the past, the value will be negative.
Declaration
Swift
public var daysUntil: Int -
The number of whole 60-minute periods until the date represented by the receiver. If the receiver is in the past, the value will be negative.
Declaration
Swift
public var hoursUntil: Int -
The number of whole 60-second periods until the date represented by the receiver. If the receiver is in the past, the value will be negative.
Declaration
Swift
public var minutesUntil: Int -
The number of whole seconds until the date represented by the receiver. If the receiver is in the past, the value will be negative.
Declaration
Swift
public var secondsUntil: Int
-
The number of whole 7-day periods since the date represented by the receiver. If the receiver is in the future, the value will be negative.
Declaration
Swift
public var weeksSince: Int -
The number of whole 24-hour periods since the date represented by the receiver. If the receiver is in the future, the value will be negative.
Declaration
Swift
public var daysSince: Int -
The number of whole 60-minute periods since the date represented by the receiver. If the receiver is in the future, the value will be negative.
Declaration
Swift
public var hoursSince: Int -
The number of whole 60-second periods since the date represented by the receiver. If the receiver is in the future, the value will be negative.
Declaration
Swift
public var minutesSince: Int -
The number of whole seconds since the date represented by the receiver. If the receiver is in the future, the value will be negative.
Declaration
Swift
public var secondsSince: Int
-
Returns a new
Dateset to the same day as the receiver but with a time changed to the specified hour, minute, second and nanosecond.Declaration
Swift
public func changedTime(hour: Int, minute: Int, second: Int, nanosecond: Int) -> DateParameters
hourThe hour component for the returned time.
minuteThe minute component for the returned time.
secondThe second component for the returned time.
nanosecondThe nanosecond component for the returned time.
Return Value
The new
Datewith the time changed. -
Returns a new
Daterepresenting the 24-hour time00:00:00on the same day as the receiver.Declaration
Swift
public var startOfDay: Date -
Returns a new
Daterepresenting the 24-hour time23:59:59.999999999on the same day as the receiver.Declaration
Swift
public var endOfDay: Date -
Returns a new
Daterepresenting the current time, but with yesterday’s date.Declaration
Swift
public static var yesterday: Date -
Returns a new
Daterepresenting the current time, but with tomorrow’s date.Declaration
Swift
public static var tomorrow: Date -
Returns a new
Datecontaining the same time as the receiver, but with the date adjusted earlier or later by the given number of days.Declaration
Swift
public func adjustDay(_ days: Int) -> DateParameters
daysThe number of days to add to (if positive) or subtract from (if negative) the receiver.
Return Value
The new
Dateinstance. -
Returns a new
Datecontaining the same time as the receiver, but one day earlier.Declaration
Swift
public var dayBefore: DateReturn Value
The new
Dateinstance. -
Returns a new
Datecontaining the same time as the receiver, but one day later.Declaration
Swift
public var dayAfter: DateReturn Value
The new
Dateinstance.
-
trueif the receiver represents a time in the past;falseotherwise.Declaration
Swift
public var isPast: Bool -
trueif the receiver represents the current time;falseotherwise.Declaration
Swift
public var isNow: Bool -
trueif the receiver represents a time in the future;falseotherwise.Declaration
Swift
public var isFuture: Bool -
trueif the receiver represents any time yesterday;falseotherwise.Declaration
Swift
public var isYesterday: Bool -
trueif the receiver represents any time today;falseotherwise.Declaration
Swift
public var isToday: Bool -
trueif the receiver represents any time tomorrow;falseotherwise.Declaration
Swift
public var isTomorrow: Bool -
trueif the receiver represents any time before today;falseotherwise.Declaration
Swift
public var isBeforeToday: Bool -
trueif the receiver represents any time after today;falseotherwise.Declaration
Swift
public var isAfterToday: Bool -
Determines if the receiver represents a time between two given times or is equal to one of the times.
Note: The order of the
time1andtime2arguments is not significant; they may be swapped without changing the return value of the function.Declaration
Swift
public func isBetween(_ time1: Date, and time2: Date) -> BoolParameters
time1The first
Datevalue.time2The second
Datevalue.Return Value
trueif the receiver represents any time betweentime1andtime2(inclusive);falseotherwise. -
Determines if the current time falls between two given times or is equal to one of the times.
Note: The order of the
time1andtime2arguments is not significant; they may be swapped without changing the return value of the function.Declaration
Swift
public static func currentTimeIsBetween(_ time1: Date, and time2: Date) -> BoolParameters
time1The first
Datevalue.time2The second
Datevalue.Return Value
trueif the current time is betweentime1andtime2(inclusive);falseotherwise. -
Determines whether the specified
Daterepresents the same day as the receiver.Declaration
Swift
public func isSameDayAs(_ date: Date) -> BoolParameters
dateThe date to test.
Return Value
trueifdaterepresents any time on the same day as the receiver;falseotherwise.
-
Formats the receiver as a date string using the specified
DateFormatter.Style.Declaration
Swift
public func formatDate(style: DateFormatter.Style, timeZone: TimeZone? = nil) -> StringParameters
styleThe
DateFormatter.Stylethat specifies the format of the string to be returned.timeZoneThe
TimeZoneassociated with the date being formatted. Ifnil, the time zone will not be taken into account.Return Value
The string representation of the receiver’s date.
-
Formats the receiver as a time string using the specified
DateFormatter.Style.Declaration
Swift
public func formatTime(style: DateFormatter.Style, timeZone: TimeZone? = nil) -> StringParameters
styleThe
DateFormatter.Stylethat specifies the format of the string to be returned.timeZoneThe
TimeZoneassociated with the time being formatted. Ifnil, the time zone will not be taken into account.Return Value
The string representation of the receiver’s time.
-
Formats the receiver as a date/time string using the specified
DateFormatter.Style.Declaration
Swift
public func formatDateTime(style: DateFormatter.Style, timeZone: TimeZone? = nil) -> StringParameters
styleThe
DateFormatter.Stylethat specifies the format of the string to be returned.timeZoneThe
TimeZoneassociated with the date and time being formatted. Ifnil, the time zone will not be taken into account.Return Value
The string representation of the receiver’s date and time.
-
Formats the receiver as a date string in the UTC time zone using the specified
DateFormatter.Style.Declaration
Swift
public func formatUTCDate(style: DateFormatter.Style) -> StringParameters
styleThe
DateFormatter.Stylethat specifies the format of the string to be returned.Return Value
The string representation of the receiver’s date.
-
Formats the receiver as a time string in the UTC time zone using the specified
DateFormatter.Style.Declaration
Swift
public func formatUTCTime(style: DateFormatter.Style) -> StringParameters
styleThe
DateFormatter.Stylethat specifies the format of the string to be returned.Return Value
The string representation of the receiver’s time.
-
Formats the receiver as a date/time string in the UTC time zone using the specified
DateFormatter.Style.Declaration
Swift
public func formatUTCDateTime(style: DateFormatter.Style) -> StringParameters
styleThe
DateFormatter.Stylethat specifies the format of the string to be returned.Return Value
The string representation of the receiver’s date and time.
-
Formats the receiver as a date/time string using the specified
DateFormatvalue.Declaration
Swift
public func asString(format: StandardDateFormat, timeZone: TimeZone) -> StringParameters
formatA
DateFormatvalue specifying the format of the string to be returned.timeZoneThe
TimeZoneassociated with the date being formatted.Return Value
The string representation of the receiver’s date and time.
-
Formats the receiver as a date/time string using the specified
DateFormatvalue.Declaration
Swift
public func asString(format: StandardDateFormat, inLocalTime: Bool = false) -> StringParameters
formatA
DateFormatvalue specifying the format of the string to be returned.inLocalTimeIf
true, the returned string will represent the user’s local time; otherwise, UTC time is used.Return Value
The string representation of the receiver’s date and time.
-
Formats the receiver as an RFC 1123 date/time string.
Declaration
Swift
public func asRFC1123(inLocalTime: Bool = false) -> StringParameters
inLocalTimeIf
true, the returned string will represent the user’s local time; otherwise, UTC time is used.Return Value
The string representation of the receiver’s date and time.
-
Formats the receiver as an ISO 8601 date/time string.
Declaration
Swift
public func asISO8601(inLocalTime: Bool = false) -> StringParameters
inLocalTimeIf
true, the returned string will represent the user’s local time; otherwise, UTC time is used.Return Value
The string representation of the receiver’s date and time.
-
The
yearcomponent of the date represented by the receiver.Declaration
Swift
public var year: Int -
The
monthcomponent of the date represented by the receiver.Declaration
Swift
public var month: Int -
The
day(of the month) component of the date represented by the receiver.Declaration
Swift
public var day: Int -
The
hourcomponent of the date represented by the receiver.Declaration
Swift
public var hour: Int -
The
minutecomponent of the date represented by the receiver.Declaration
Swift
public var minute: Int -
The
secondcomponent of the date represented by the receiver.Declaration
Swift
public var second: Int -
The
nanosecondcomponent of the date represented by the receiver.Declaration
Swift
public var nanosecond: Int -
The
weekdaycomponent of the date represented by the receiver. This is a value between 1 and n (inclusive). In the Gregorian calendar, 1 represents Sunday, while n is 7, representing Saturday.Declaration
Swift
public var weekday: Int -
The
weekdayOrdinalcomponent of the date represented by the receiver. This value indicates the currentweekday‘s ordinal position within the currentmonth. In the Gregorian calendar, aweekdayOrdinalunit of 3 for aweekdayof 4 representsthe third Wednesday in the month.
Declaration
Swift
public var weekdayOrdinal: Int -
The
weekOfMonthcomponent of the date represented by the receiver.Declaration
Swift
public var weekOfMonth: Int -
The
weekOfYearcomponent of the date represented by the receiver.Declaration
Swift
public var weekOfYear: Int -
The
timeZonecomponent of the date represented by the receiver, ornilif it could not be determined.Declaration
Swift
public var timeZone: TimeZone?
View on GitHub
Date Extension Reference