iPhone - 如何获取用户的日期格式

问题描述:

我如何知道用户喜欢什么日期格式?有没有办法从手机的本地设置读取它?用户是否希望以dd / mm / yyyy或mm / dd / yyyy格式读取日期?

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"?

提前感谢。

使用NSDateFormatter,但是设置样式(不是格式),因此它使用用户的区域设置格式。

Use NSDateFormatter, but set the style (not the format) so it uses the user's locale formats.

例如。创建一个NSDateFormatter并进行配置

e.g. create an NSDateFormatter and configure it thusly

[dateFormatter setDateStyle:NSDateFormatterShortStyle];

(对于mm / dd / yy类型日期,在其他国家/地区为dd / mm / yy)

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