Date

extension Date
  • TimeFormat is an enum for formatting timestamps.

    Given an hour, minute, and second, the time will be formatted in one of four formats.

    • hourMinuteMilitary (e.g. 19:41)
    • hourMinutePeriod (e.g. 07:41 PM)
    • hourMinuteSecondMilitary (e.g. 19:41:30)
    • hourMinuteSecondPeriod (e.g. 07:41:30 PM)
    See more

    Declaration

    Swift

    public enum TimeFormat
  • Returns a Date value initialized with the provided month, day, and year

    Declaration

    Swift

    public init?(month: Int, day: Int, year: Int)

    Parameters

    month

    The month

    day

    The day

    year

    The year

    Return Value

    A Date value initialized with the provided month, day, and year

  • era

    The era component of self

    Declaration

    Swift

    public var era: Int { get }
  • The year component of self

    Declaration

    Swift

    public var year: Int { get }
  • The month component of self

    Declaration

    Swift

    public var month: Int { get }
  • day

    The day component of self

    Declaration

    Swift

    public var day: Int { get }
  • The hour component of self

    Declaration

    Swift

    public var hour: Int { get }
  • The minute component of self

    Declaration

    Swift

    public var minute: Int { get }
  • The second component of self

    Declaration

    Swift

    public var second: Int { get }
  • The weekday component of self

    Declaration

    Swift

    public var weekday: Int { get }
  • The weekdayOrdinal component of self

    Declaration

    Swift

    public var weekdayOrdinal: Int { get }
  • The quarter component of self

    Declaration

    Swift

    public var quarter: Int { get }
  • The weekOfMonth component of self

    Declaration

    Swift

    public var weekOfMonth: Int { get }
  • The weekOfYear component of self

    Declaration

    Swift

    public var weekOfYear: Int { get }
  • The yearForWeekOfYear component of self

    Declaration

    Swift

    public var yearForWeekOfYear: Int { get }
  • The nanosecond component of self

    Declaration

    Swift

    public var nanosecond: Int { get }
  • The calendar component of self

    Declaration

    Swift

    public var calendar: Calendar? { get }
  • The timeZone component of self

    Declaration

    Swift

    public var timeZone: TimeZone? { get }
  • The time, formatted with a specified TimeFormat.

    Format options:

    • HourMinuteMilitary (e.g. 19:41)
    • HourMinutePeriod (e.g. 07:41 PM)
    • HourMinuteSecondMilitary (e.g. 19:41:30)
    • HourMinuteSecondPeriod (e.g. 07:41:30 PM)

    Default format is HourMinuteMilitary.

    Declaration

    Swift

    public func time(format: TimeFormat = .hourMinuteMilitary) -> String

    Parameters

    format

    The format to use for the time (optional).

    Return Value

    The formatted time string.