Date

extension Date
  • Returns the local date string like “May 2019”

    Declaration

    Swift

    var MMMM_yyyy: String { get }
  • Returns the local date string like “18.08.2019”

    Declaration

    Swift

    var ddMMyyyy: String { get }
  • Returns the local date string including day, like “Sunday 18.08.2019”

    Declaration

    Swift

    var EEEEddMMyyyy: String { get }
  • Returns the local time string like “20:44:23”

    Declaration

    Swift

    var HHmmss: String { get }
  • Returns the local time string with milliseconds, like “12:00:00.000”

    Declaration

    Swift

    var HHmmssSSS: String { get }
  • Initializes self to the date at the specified secondsInto21stCentury

    Declaration

    Swift

    init(seconds secondsInto21stCentury: TimeInterval)

    Parameters

    secondsInto21stCentury

    seconds since 00:00:00 UTC on 1 January 2001

  • Returns the detailed local date-time string, like “24.07.2019 10:00:00”

    Declaration

    Swift

    var ddMMyyyy_HHmmss: String { get }
  • Returns the detailed local date-time string, like “Wednesday 24.07.2019 10:00:00”

    Declaration

    Swift

    var EEEE_ddMMyyyy_HHmmss: String { get }
  • Returns the detailed local date-time string, like “Wednesday 24.07.2019 10:00:00 +02:00”

    Declaration

    Swift

    var EEEE_ddMMyyyy_HHmmss_ZZZZZ: String { get }
  • Returns a timestamp (timeIntervalSince1970)

    Declaration

    Swift

    var timeStamp: TimeInterval { get }
  • Returns a timestamp string (timeIntervalSince1970), like “1566153863_69661”

    Declaration

    Swift

    var timeTag: String { get }

modifiers

  • Increments self by component and value

    Declaration

    Swift

    mutating func increment(by component: Calendar.Component, times value: Int)

    Parameters

    component

    a Calendar.Component like .hour, .day, .month, …

    value

    number of compoents (hous, days, months, …)

  • Date incremented by component and value

    Declaration

    Swift

    func incremented(by component: Calendar.Component, times value: Int) -> Date
  • Increments self by 1 month

    Declaration

    Swift

    mutating func nextMonth()
  • Decrements self by 1 month

    Declaration

    Swift

    mutating func prevMonth()
  • Returns a date with the day of month modified

    Preserves the .hour, sets .minute and smaller components to 0

    Declaration

    Swift

    func setting(day: Int) -> Date?

    Parameters

    day

    day of month (1…) to set to

    Return Value

    modified copy of self or nil if invalid date would be generated

  • Modifies self, setting the day of month

    Preserves the .hour, sets .minute and smaller components to 0

    Declaration

    Swift

    mutating func set(day: Int)

    Parameters

    day

    day of month (1…) to set to

  • Returns a date with the hour modified

    Sets .minute and smaller components to 0

    Declaration

    Swift

    func setting(hour: Int) -> Date?

    Parameters

    hour

    hour to set to (0…23)

    Return Value

    modified copy of self or nil if invalid date would be generated

  • Modifies self, setting the hour

    Sets .minute and smaller components to 0

    Declaration

    Swift

    mutating func set(hour: Int)

    Parameters

    hour

    hour to set to (0…23)

  • Returns a date setting the hour, minute, second all to 0

    Declaration

    Swift

    func zeroingHms() -> Date?

    Return Value

    modified copy of self or nil if invalid date would be generated

  • Modifies self, setting the hour, minute, second all to 0

    Declaration

    Swift

    mutating func zeroHms()
  • Returns a date setting the minute, second all to 0

    Declaration

    Swift

    var wholeHour: Date? { get }

    Return Value

    modified copy of self or nil if invalid date would be generated

  • Returns a date setting the hour, minute, second all to 0

    Declaration

    Swift

    var wholeDay: Date? { get }

    Return Value

    modified copy of self or nil if invalid date would be generated

  • Returns a date setting the day to 1, hour, minute, second all to 0

    Declaration

    Swift

    var wholeMonth: Date? { get }

    Return Value

    modified copy of self or nil if invalid date would be generated

properties

  • Returns month (1..12)

    Declaration

    Swift

    var month: Int { get }
  • Returns month (0..11)

    Declaration

    Swift

    var month_0: Int { get }
  • Returns the start date of the month

    Declaration

    Swift

    var month1st: Date { get }
  • Returns the last date of the month

    Declaration

    Swift

    var monthLast: Date { get }
  • Returns an array of days. ex. [1, 2, …, 31]

    Declaration

    Swift

    var daysInMonth: [Int] { get }
  • Returns year

    Declaration

    Swift

    var year: Int { get }
  • day

    Returns day in month (1…)

    Declaration

    Swift

    var day: Int { get }
  • Returns day in month (0…)

    Declaration

    Swift

    var day_0: Int { get }
  • Returns weekdayOrdinal (range 1…5, 1 for 1st 7 days of the month, 2 for next 7 days, etc)

    Declaration

    Swift

    var weekdayOrdinal: Int { get }
  • Returns weekday (1…7, 1 is Sunday)

    Declaration

    Swift

    var weekday: Int { get }
  • Returns weekday (0…6, 0 is Monday)

    Declaration

    Swift

    var weekday_0M: Int { get }
  • Returns weekday (1…7, 1 is Sunday) of the first day of the month

    Declaration

    Swift

    var month1stWeekday: Int { get }
  • Returns weekday (0…6, 0 is Monday) of the first day of the month

    Declaration

    Swift

    var month1stWeekday_0M: Int { get }
  • Returns true if self is today (any hour)

    Declaration

    Swift

    var isToday: Bool { get }
  • Returns hour (0..23)

    Declaration

    Swift

    var hour: Int { get }
  • Returns the date interval of component duration which contains self

    Declaration

    Swift

    func dateInterval(of component: Calendar.Component) -> DateInterval?

    Parameters

    component

    calendar component