NSDateComponentsFormatter is what you want. It may not create exactly what you are looking for, but my impression is that it aims to produce products that comply with standard ICU agreements. For example, consider the following:
NSDateComponentsFormatter* dcf = [[NSDateComponentsFormatter alloc] init]; dcf.unitsStyle = NSDateComponentsFormatterUnitsStyleAbbreviated; NSCalendar* cal = [NSCalendar calendarWithIdentifier: NSCalendarIdentifierGregorian]; cal.locale = [NSLocale localeWithLocaleIdentifier: @"es_ES"];
... which produces:
1 semana, 4 d, 13 h, 46 min, 40 s
So, this is a little different from the format of your example, but I assume somewhere deep in the Unicode ICU standards documents it says that if the interval is weeks and seconds, then you get a "semann" for several weeks instead of "s". I am not going to torture myself trying to find this document.
So, if you are looking for an ICU solution, this is it. If you are looking for something else, you can freeze yourself. Also note that there are several different โunit stylesโ so that you can try others and choose the one that best suits your situation.
ipmcc
source share