Mail.app style relative date formatter. A reimplementation of TFGRelativeDateFormatter written in Swift.
en_GB | en_US | |
---|---|---|
Same Day | 13:45 | 1:45 PM |
Yesterday | Yesterday | Yesterday |
Same Week | Monday | Monday |
Same Year | 15 Mar | Mar 15 |
Last Year | 22/04/2013 | 4/22/13 |
RelativeDateFormatter
instances should be cached where possible, similar to
DateFormatter
they are expensive to initialize.
let date = ...
let formatter = RelativeDateFormatter()
let relativeString = formatter.string(from: date)
Or, for a string relative to some other date:
let date = ...
let otherDate = ...
let formatter = RelativeDateFormatter()
let relativeString = formatter.string(from: date, relativeTo: otherDate)
RelativeDateFormatter is released under the MIT License.