localizedString(fromTimeInterval:)
Formats the specified time interval using the formatter’s calendar.
Declaration
func localizedString(fromTimeInterval timeInterval: TimeInterval) -> StringParameters
- timeInterval:
The time interval to format.
Return Value
A string that represents the formatted time interval.
Discussion
The formatter interprets a negative time interval as a date in the past.
let formatter = RelativeDateTimeFormatter()
print(formatter.localizedString(fromTimeInterval: -120))
// Outputs: 2 minutes ago