Date
public extension Date
-
Static method that creates a
Dateobject from a string with a given formatDeclaration
Swift
static func dateFrom(string: String, withFormat format: String) -> Date?Parameters
stringThe formatted date string
formatThe format of the string-represented date
Return Value
The created
Dateobject -
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) -> StringParameters
formatThe desired format
localeThe 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) -> StringParameters
formatThe 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
showDateShow date with long format
showTimeShow time with short format
timeZoneTime 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
dateTThe given date to calculate against
Return Value
The number of years between the given date
Date Extension Reference