删除有关用户区域设置的日期格式的年份 [英] remove year for date format in respect to the users locale
问题描述
我想显示相对于用户设备的区域设置的日期和月份。
I want to display the day and the month in respect to the locale of the users device.
因此,今天的日期将显示为 5/18 与美国设置和 18.5。与德国设置。
由于我想处理每一个可能的地区,我不能只使用 [dateFormatter setDateFormat:]
和 [dateFormatter setDateStyle:NSDateFormatterShortStyle]
将显示年份。
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?
推荐答案
我自己找到答案:
[self.dateFormatter setDateFormat:[NSDateFormatter dateFormatFromTemplate:@"MM d"
options:0
locale:[NSLocale currentLocale]]];
这篇关于删除有关用户区域设置的日期格式的年份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!