Is there some functionality in Cocoa to display time intervals in natural language?

后端 未结 4 594
轻奢々
轻奢々 2021-01-15 16:53

What I am searching for is a Cocoa (or third party) class that can display time intervals in natural language, e.g.:

  • 10 seconds ago
  • 1 hour ago
相关标签:
4条回答
  • 2021-01-15 17:38

    I can really recommend Mattt Thompson's TTTTimeIntervalFormatter - very clean, very functional (lots of other super useful bits and pieces in the same repo).

    0 讨论(0)
  • 2021-01-15 17:44

    Your question for Cocoa is the same as this question for Cocoa Touch, and the answer to that one will work for you as well, because it uses Foundation, which is in both Cocoa and Cocoa Touch.

    0 讨论(0)
  • 2021-01-15 17:51

    The one I've originally pointed to does not seem to be there anymore but as pointed out there is NSDate-TimeAgo, I haven't tried it but looks good to me.

    EDIT: updated answer to point to existing code

    0 讨论(0)
  • 2021-01-15 17:57

    See -[NSDateFormatter setDoesRelativeDateFormatting:].

    0 讨论(0)
提交回复
热议问题