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
Date
set 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) -> Date
Parameters
hour
The hour component for the returned time.
minute
The minute component for the returned time.
second
The second component for the returned time.
nanosecond
The nanosecond component for the returned time.
Return Value
The new
Date
with the time changed. -
Returns a new
Date
representing the 24-hour time00:00:00
on the same day as the receiver.Declaration
Swift
public var startOfDay: Date
-
Returns a new
Date
representing the 24-hour time23:59:59.999999999
on the same day as the receiver.Declaration
Swift
public var endOfDay: Date
-
Returns a new
Date
representing the current time, but with yesterday’s date.Declaration
Swift
public static var yesterday: Date
-
Returns a new
Date
representing the current time, but with tomorrow’s date.Declaration
Swift
public static var tomorrow: Date
-
Returns a new
Date
containing 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) -> Date
Parameters
days
The number of days to add to (if positive) or subtract from (if negative) the receiver.
Return Value
The new
Date
instance. -
Returns a new
Date
containing the same time as the receiver, but one day earlier.Declaration
Swift
public var dayBefore: Date
Return Value
The new
Date
instance. -
Returns a new
Date
containing the same time as the receiver, but one day later.Declaration
Swift
public var dayAfter: Date
Return Value
The new
Date
instance.
-
true
if the receiver represents a time in the past;false
otherwise.Declaration
Swift
public var isPast: Bool
-
true
if the receiver represents the current time;false
otherwise.Declaration
Swift
public var isNow: Bool
-
true
if the receiver represents a time in the future;false
otherwise.Declaration
Swift
public var isFuture: Bool
-
true
if the receiver represents any time yesterday;false
otherwise.Declaration
Swift
public var isYesterday: Bool
-
true
if the receiver represents any time today;false
otherwise.Declaration
Swift
public var isToday: Bool
-
true
if the receiver represents any time tomorrow;false
otherwise.Declaration
Swift
public var isTomorrow: Bool
-
true
if the receiver represents any time before today;false
otherwise.Declaration
Swift
public var isBeforeToday: Bool
-
true
if the receiver represents any time after today;false
otherwise.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
time1
andtime2
arguments 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) -> Bool
Parameters
time1
The first
Date
value.time2
The second
Date
value.Return Value
true
if the receiver represents any time betweentime1
andtime2
(inclusive);false
otherwise. -
Determines if the current time falls between two given times or is equal to one of the times.
Note: The order of the
time1
andtime2
arguments 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) -> Bool
Parameters
time1
The first
Date
value.time2
The second
Date
value.Return Value
true
if the current time is betweentime1
andtime2
(inclusive);false
otherwise. -
Determines whether the specified
Date
represents the same day as the receiver.Declaration
Swift
public func isSameDayAs(_ date: Date) -> Bool
Parameters
date
The date to test.
Return Value
true
ifdate
represents any time on the same day as the receiver;false
otherwise.
-
Formats the receiver as a date string using the specified
DateFormatter.Style
.Declaration
Swift
public func formatDate(style: DateFormatter.Style, timeZone: TimeZone? = nil) -> String
Parameters
style
The
DateFormatter.Style
that specifies the format of the string to be returned.timeZone
The
TimeZone
associated 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) -> String
Parameters
style
The
DateFormatter.Style
that specifies the format of the string to be returned.timeZone
The
TimeZone
associated 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) -> String
Parameters
style
The
DateFormatter.Style
that specifies the format of the string to be returned.timeZone
The
TimeZone
associated 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) -> String
Parameters
style
The
DateFormatter.Style
that 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) -> String
Parameters
style
The
DateFormatter.Style
that 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) -> String
Parameters
style
The
DateFormatter.Style
that 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
DateFormat
value.Declaration
Swift
public func asString(format: StandardDateFormat, timeZone: TimeZone) -> String
Parameters
format
A
DateFormat
value specifying the format of the string to be returned.timeZone
The
TimeZone
associated 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
DateFormat
value.Declaration
Swift
public func asString(format: StandardDateFormat, inLocalTime: Bool = false) -> String
Parameters
format
A
DateFormat
value specifying the format of the string to be returned.inLocalTime
If
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) -> String
Parameters
inLocalTime
If
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) -> String
Parameters
inLocalTime
If
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
year
component of the date represented by the receiver.Declaration
Swift
public var year: Int
-
The
month
component 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
hour
component of the date represented by the receiver.Declaration
Swift
public var hour: Int
-
The
minute
component of the date represented by the receiver.Declaration
Swift
public var minute: Int
-
The
second
component of the date represented by the receiver.Declaration
Swift
public var second: Int
-
The
nanosecond
component of the date represented by the receiver.Declaration
Swift
public var nanosecond: Int
-
The
weekday
component 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
weekdayOrdinal
component of the date represented by the receiver. This value indicates the currentweekday
‘s ordinal position within the currentmonth
. In the Gregorian calendar, aweekdayOrdinal
unit of 3 for aweekday
of 4 representsthe third Wednesday in the month.
Declaration
Swift
public var weekdayOrdinal: Int
-
The
weekOfMonth
component of the date represented by the receiver.Declaration
Swift
public var weekOfMonth: Int
-
The
weekOfYear
component of the date represented by the receiver.Declaration
Swift
public var weekOfYear: Int
-
The
timeZone
component of the date represented by the receiver, ornil
if it could not be determined.Declaration
Swift
public var timeZone: TimeZone?