Search code examples
iosmacoscocoadatetimeglobalization

Cocoa – locale-sensitive date/time ranges


What is the preferred locale-sensitive way to format date or time ranges, taking into account the differences in languages (e.g. right-to-left) and differences in calendars (e.g. Islamic calendar).

For example, I'm looking to format date ranges such as these:

1-Jan-2015 – 7-Jan-2015

Taking into account that different cultures may may prefer other symbols than "–" to express ranges and they may read from right to left, hence prefer the smaller date on the right.

I'm looking for something that is workable in both iOS and OS X.


Solution

  • If you can require OS X 10.10+ and iOS 8+, that's what NSDateIntervalFormatter is for.