How can I know what date format user prefers? Is there a way to read it from phone's local settings? Does the user prefer to read date in format "dd/mm/yyyy" or "mm/dd/yyyy"?
Thank you in advance.
How can I know what date format user prefers? Is there a way to read it from phone's local settings? Does the user prefer to read date in format "dd/mm/yyyy" or "mm/dd/yyyy"?
Thank you in advance.
Use NSDateFormatter, but set the style (not the format) so it uses the user's locale formats.
e.g. create an NSDateFormatter and configure it thusly
(for mm/dd/yy type dates, which are dd/mm/yy in other countries)
CFDateFormatter
Should do the trick.
Since iOS 6 you can use "localizedStringFromDate"
Just in case you want the locale settings before formatting a date, you need to use NSLocale, like so:
This contains a slew of information about the current locale settings - read the docs for detailed info.
To know which format user prefer: i used [[dateFormatter locale] localeIdentifier] . If it returns en_US it means date is in mm/dd/yyyy format otherwise dd/mm/yyyy format. dateFormatter is an instance of NSDateFormatter class.
Vishwa, the US isn't the only country to use the "mm/dd/yyy" format, and "dd/mm/yyyy" isn't the only alternative.
See http://en.wikipedia.org/wiki/Calendar_date#List_of_the_world_locations_by_date_format_in_use for more info.