Date

struct Date : ReferenceConvertible, Comparable, Equatable
  • now

    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 more

    Declaration

    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 with timespec struct.

    Declaration

    Swift

    init(timespec: timespec)

    Parameters

    timespec

    A timespec struct.

  • Undocumented

    Declaration

    Swift

    struct Date : ReferenceConvertible, Comparable, Equatable
  • era

    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 used

    Declaration

    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 used

    Declaration

    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 used

    Declaration

    Swift

    var month: Int
  • day

    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 used

    Declaration

    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 used

    Declaration

    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 used

    Declaration

    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 used

    Declaration

    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 used

    Declaration

    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 used

    Declaration

    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 used

    Declaration

    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 used

    Declaration

    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 used

    Declaration

    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 used

    Declaration

    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 used

    Declaration

    Swift

    var yearForWeekOfYear: Int
  • Converting the right hand side argument Duration to DateComponents first and add it to the left hand side Date 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 to DateComponents first and minus it to the left hand side Date 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