I am trying to make my iPhone app accessible. Part of it involves generating accessible VoiceOver labels for the time and date parts of an NSDate
. How do I format an NSDate
in an accessible way that will work correctly in all languages that VoiceOver supports?
NSDateFormatter has a method called localizedStringFromDate:dateStyle:timeStyle:
that handles the localization automatically. Pass it a date and NSDateFormatterStyles for each the date and time portions. Note that you may want different styles for the date and time if you want something that reads nicely with voiceover. NSDateFormatterLongStyle works well for the date in most cases (as you get the month fully spelled out), while NSDateFormatterShortStyle works well for the time (as it doesn't include seconds).
More information: https://developer.apple.com/documentation/foundation/dateformatter/1415241-localizedstring
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With