Re: How to Display a Time Interval

Gary L. Wade

Sorry, forgot the last part.  After you get the components using the calendar you wish to use with your two dates, then call NSDateComponentsFormatter.  For a simple case, you could get by with:

+ (nullable NSString *)localizedStringFromDateComponents:(NSDateComponents *)components unitsStyle:(NSDateComponentsFormatterUnitsStyle) unitsStyle;

On May 19, 2019, at 11:13 AM, Gary L. Wade <garywade@...> wrote:

Use NSCalendar’s method:

- (NSDateComponents *)components:(NSCalendarUnit)unitFlags fromDate:(NSDate *)startingDate toDate:(NSDate *)resultDate options:(NSCalendarOptions)opts;

On May 19, 2019, at 3:02 AM, Dave <dave@...> wrote:

Objective-C, Mac.


I’m trying to display a countdown to a date in the future e.g. the number of years, weeks and days to 1/1/2021.

I have the Time Interval between now and the future date in seconds, but I can’t seem to find any methods to display this in terms of years. months, weeks, days etc.

Is there a method or class somewhere that does this or do I need to roll my own?

All the Best

Join to automatically receive all group messages.