Search code examples
iphonecocoa-touchlocale

iPhone - how to get user's date format


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.


Solution

  • 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

    [dateFormatter setDateStyle:NSDateFormatterShortStyle];
    

    (for mm/dd/yy type dates, which are dd/mm/yy in other countries)