Re: How to Display a Time Interval


 



On May 19, 2019, at 3:42 AM, Peter Hudson via Groups.Io <Peter.hudson@...> wrote:

I seem to remember using NSCalendatDate  and the descriptionWithCalendarFormat:   method to get what you want.
NSCalendarDate is now deprecated - the docs advocate the use of NSDate, NSCalendar, NSDateComponents to do the job now.
You have to roll the final string yourself - as far as I can see...

You want NSDateComponentsFormatter:

/* NSDateComponentsFormatter provides locale-correct and flexible string formatting of quantities of time, such as "1 day" or "1h 10m", as specified by NSDateComponents. For formatting intervals of time (such as "2PM to 5PM"), see NSDateIntervalFormatter. NSDateComponentsFormatter is thread-safe, in that calling methods on it from multiple threads will not cause crashes or incorrect results, but it makes no attempt to prevent confusion when one thread sets something and another thread isn't expecting it to change.

Join cocoa@apple-dev.groups.io to automatically receive all group messages.