remove year for date format in respect to the users locale

此生再无相见时 提交于 2019-12-10 18:34:17

问题


I want to display the day and the month in respect to the locale of the users device.

So that the date of today would be displayed as 5/18 with american settings and 18.5. with german setting.
As I want to handle every possible locale, I cant just simply use the [dateFormatter setDateFormat:] and [dateFormatter setDateStyle:NSDateFormatterShortStyle] will display the year.

Beside trying to identify the year value in the string and removeing it, is there a more elegant way?


回答1:


I found the answer myself:

[self.dateFormatter setDateFormat:[NSDateFormatter dateFormatFromTemplate:@"MM d"
                                                                  options:0 
                                                                   locale:[NSLocale currentLocale]]];

See more at apple documentation on dateFormatFromTemplate



来源:https://stackoverflow.com/questions/10654645/remove-year-for-date-format-in-respect-to-the-users-locale

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!