Search code examples
iosobjective-clocalizationnsdatensdateformatter

Getting localized date range string from two NSDates


I'm running into an issue when it comes to taking two NSDates and displaying a localized string for the range.

For example, say my dates are on July 7 and July 9. I would need the following localized strings:

  • EN: July 7-9
  • FR: 7-9 Juliet
  • ES: 7-9 Julio
  • DE: 7. bis. 9. Juli

Obviously using NSString stringWithFormat: isn't going to work here. For the sake of simplicity, let's not even get into the case where your range is two separate months. I know how to get a formatted string for each date but it's formatting it in a range that is getting me.

Is there way of using an NSDateFormatter to get this? The more I look around, the more I think I'm going to need to have a switch for each locale.

EDIT: To clarify, I only need the date range for the user's locale. I don't need all of them at the same time.


Solution

  • After further research it looks like in iOS 8.0+ you can use NSDateIntervalFormatter to do this. That doesn't help me now but it's comforting to know it's on the way.