Date

public extension Date
  • Static method that creates a Date object from a string with a given format

    Declaration

    Swift

    static func dateFrom(string: String, withFormat format: String) -> Date?

    Parameters

    string

    The formatted date string

    format

    The format of the string-represented date

    Return Value

    The created Date object

  • Instance method that creates a formatted dates string using the default locale (en_US_POSIX) and a specified format

    Declaration

    Swift

    func string(withFormat format: String, locale: Locale? = nil) -> String

    Parameters

    format

    The desired format

    locale

    The locale that will be used

  • Instance method that creates a formatted date string from the current locale using a specified format

    Declaration

    Swift

    func localizedString(withFormat format: String) -> String

    Parameters

    format

    The desired format

    Return Value

    The formatted date string

  • Instance method that creates a formatted string of the date using the specified format

    Declaration

    Swift

    func formattedStringWithDate(showDate: Bool,
                                 showTime: Bool,
                                 timeZone: TimeZone = .current) -> String?

    Parameters

    showDate

    Show date with long format

    showTime

    Show time with short format

    timeZone

    Time zone that will be used

    Return Value

    The formatted date string

  • Instance method that calculates the number of years between a given date

    Declaration

    Swift

    func numberOfYears(fromDate date: Date) -> Int?

    Parameters

    date

    TThe given date to calculate against

    Return Value

    The number of years between the given date