Date
struct Date : ReferenceConvertible, Comparable, Equatable
-
Alias to
Date#new
returns a new date with current date time.Declaration
Swift
static var now: Date
-
Returns a new Date representing the date 1 day after today
Declaration
Swift
static var tommorow: Date
-
Returns a new Date representing the date 1 day before today
Declaration
Swift
static var yesterday: Date
-
Returns a date with timestamp, use
Date(timeIntervalSince1970:)
initializer to create a new date.Declaration
Swift
static func at(_ timestamp: Int) -> Date
Parameters
timestamp
A unix timestamp
Return Value
A date
-
Returns a date with timestamp, use
Date(timeIntervalSince1970:)
initializer to create a new date.Declaration
Swift
static func at(_ timestamp: Double) -> Date
Parameters
timestamp
A unix timestamp
Return Value
A date
-
Returns a new Date where one or more of the elements have been changed according to the passing parameter.
Declaration
Swift
func change(year: Int? = nil, month: Int? = nil, day: Int? = nil, hour: Int? = nil, minute: Int? = nil, second: Int? = nil) -> Date
Parameters
year
A int value
month
A int value
day
A int value
hour
A int value
minute
A int value
second
A int value
Return Value
A new date
-
Returns and changes
self
where one or more of the elements have been changed according to the passing parameter.Declaration
Swift
mutating func changed(year: Int? = nil, month: Int? = nil, day: Int? = nil, hour: Int? = nil, minute: Int? = nil, second: Int? = nil) -> Date
Parameters
year
A int value
month
A int value
day
A int value
hour
A int value
minute
A int value
second
A int value
Return Value
Self
-
Undocumented
See moreDeclaration
Swift
struct Date : ReferenceConvertible, Comparable, Equatable
-
Adjusts receiver and returns an new date with corresponding time period.
Declaration
Swift
func at(_ period: Period) -> Date
Parameters
period
An enum specify time period
Return Value
A new date
-
Converts Date with the time portion set to the beginning of the day (0:00)
Declaration
Swift
var beginningOfDay: Date
-
Converts Date with the time portion set to the beginning of the day (0:00)
Declaration
Swift
var midnight: Date
-
Converts Date with the time portion set to the middle of the day (12:00)
Declaration
Swift
var middleOfDay: Date
-
Converts Date with the time portion set to the middle of the day (12:00)
Declaration
Swift
var midday: Date
-
Converts Date with the time portion set to the middle of the day (12:00)
Declaration
Swift
var noon: Date
-
Converts Date with the time portion set to the end of the day (23:59:59)
Declaration
Swift
var endOfDay: Date
-
Returns a date object denoting the following day.
Declaration
Swift
var next: Date
-
Returns a date object denoting the following day.
Declaration
Swift
var nextDay: Date
-
Returns a date object denoting the following month.
Declaration
Swift
var nextMonth: Date
-
Returns a date object denoting the following year.
Declaration
Swift
var nextYear: Date
-
Returns a date object denoting the previous day.
Declaration
Swift
var prevDay: Date
-
Returns a date object denoting the previous month.
Declaration
Swift
var prevMonth: Date
-
Returns a date object denoting the previous year.
Declaration
Swift
var prevYear: Date
-
Returns a date object pointing other days after self. The other should be a numeric value.
Declaration
Swift
func nextDay(_ n: Int = 1) -> Date
Parameters
n
A integer value
Return Value
A new date
-
Returns a date object pointing n months after self. The argument n should be a numeric value.
Declaration
Swift
func nextMonth(_ n: Int = 1) -> Date
Parameters
n
A integer value
Return Value
A new date
-
Returns a date object pointing n years after self. The argument n should be a numeric value.
Declaration
Swift
func nextYear(_ n: Int = 1) -> Date
Parameters
n
A integer value
Return Value
A new date
-
Returns a date object pointing other days before self. The other should be a numeric value.
Declaration
Swift
func prevDay(_ n: Int = 1) -> Date
Parameters
n
A integer value
Return Value
A new date
-
Returns a date object pointing n months before self. The argument n should be a numeric value.
Declaration
Swift
func prevMonth(_ n: Int = 1) -> Date
Parameters
n
A integer value
Return Value
A new date
-
Returns a date object pointing n years before self. The argument n should be a numeric value.
Declaration
Swift
func prevYear(_ n: Int = 1) -> Date
Parameters
n
A integer value
Return Value
A new date
-
Undocumented
Declaration
Swift
struct Date : ReferenceConvertible, Comparable, Equatable
-
Returns a date from given string or nil.
Date#parse(str:)
can only parse string in several forms.See
See Also:DateFormat#parse(str:)
Declaration
Swift
static func parse(str: String) -> Date?
Parameters
str
A string
Return Value
A date object or nil
-
Undocumented
Declaration
Swift
struct Date : ReferenceConvertible, Comparable, Equatable
-
Undocumented
Declaration
Swift
struct Date : ReferenceConvertible, Comparable, Equatable
-
Creates a
Date
instance withtimespec
struct.Declaration
Swift
init(timespec: timespec)
Parameters
timespec
A timespec struct.
-
Returns true if the date is Sunday.
Declaration
Swift
var isSunday: Bool
-
Returns true if the date is Monday.
Declaration
Swift
var isMonday: Bool
-
Returns true if the date is Tuesday.
Declaration
Swift
var isTuesday: Bool
-
Returns true if the date is Wednesday.
Declaration
Swift
var isWednesday: Bool
-
Returns true if the date is Thursday.
Declaration
Swift
var isThursday: Bool
-
Returns true if the date is Friday.
Declaration
Swift
var isFriday: Bool
-
Returns true if the date is Saturday.
Declaration
Swift
var isSaturday: Bool
-
Returns true if the date is leap year.
Declaration
Swift
var isLeapYear: Bool
-
Undocumented
Declaration
Swift
struct Date : ReferenceConvertible, Comparable, Equatable
-
The number of era units for the receiver.
Note
This value is interpreted in the context of the calendar and timezone with which it is usedDeclaration
Swift
var era: Int
-
The number of year units for the receiver.
Note
This value is interpreted in the context of the calendar and timezone with which it is usedDeclaration
Swift
var year: Int
-
The number of month units for the receiver.
Note
This value is interpreted in the context of the calendar and timezone with which it is usedDeclaration
Swift
var month: Int
-
The number of day units for the receiver.
Note
This value is interpreted in the context of the calendar and timezone with which it is usedDeclaration
Swift
var day: Int
-
The number of hour units for the receiver.
Note
This value is interpreted in the context of the calendar and timezone with which it is usedDeclaration
Swift
var hour: Int
-
The number of minute units for the receiver.
Note
This value is interpreted in the context of the calendar and timezone with which it is usedDeclaration
Swift
var minute: Int
-
The number of second units for the receiver.
Note
This value is interpreted in the context of the calendar and timezone with which it is usedDeclaration
Swift
var second: Int
-
The number of nanosecond units for the receiver.
Note
This value is interpreted in the context of the calendar and timezone with which it is usedDeclaration
Swift
var nanosecond: Int
-
The number of weekday units for the receiver.
Note
This value is interpreted in the context of the calendar and timezone with which it is usedDeclaration
Swift
var weekday: Int
-
The number of weekdayOrdinal units for the receiver.
Note
This value is interpreted in the context of the calendar and timezone with which it is usedDeclaration
Swift
var weekdayOrdinal: Int
-
The number of quarter units for the receiver.
Note
This value is interpreted in the context of the calendar and timezone with which it is usedDeclaration
Swift
var quarter: Int
-
The number of weekOfMonth units for the receiver.
Note
This value is interpreted in the context of the calendar and timezone with which it is usedDeclaration
Swift
var weekOfMonth: Int
-
The number of weekOfYear units for the receiver.
Note
This value is interpreted in the context of the calendar and timezone with which it is usedDeclaration
Swift
var weekOfYear: Int
-
The number of yearForWeekOfYear units for the receiver.
Note
This value is interpreted in the context of the calendar and timezone with which it is usedDeclaration
Swift
var yearForWeekOfYear: Int
-
Returns a new date with utc format.
Declaration
Swift
var to_utc: Date
-
Returns a new date with utc format.
Declaration
Swift
var utc: Date
-
Converting the right hand side argument
Duration
toDateComponents
first and add it to the left hand sideDate
object.let date = Date(str: "2017-01-01 00:00:00 +0000")! date + 1.year #=> 2018-01-01 00:00:00 +0000 date + 2.years #=> 2019-01-01 00:00:00 +0000 date + 2.years + 1.month #=> 2019-02-01 00:00:00 +0000
Declaration
Swift
static func +(lhs: Date, rhs: Duration) -> Date
Parameters
lhs
A date
rhs
A duration
Return Value
A new date which add the duration to the old date
-
Converting the right hand side argument
Duration
toDateComponents
first and minus it to the left hand sideDate
object.let date = Date(str: "2017-01-01 00:00:00 +0000")! date - 1.year #=> 2016-01-01 00:00:00 +0000 date - 2.years #=> 2015-01-01 00:00:00 +0000
Declaration
Swift
static func -(lhs: Date, rhs: Duration) -> Date
Parameters
lhs
A date
rhs
A duration
Return Value
A new date which minus the duration to the old date