如何解决 objective c 中的日期格式问题
How to solve Problem with date format in objective c
我在中文语言中遇到日期格式问题我想显示工作日月份但得到的输出为月份日工作日下面是我使用的代码
_iconDateFormatter.locale = NSLocale.currentLocale;
[_iconDateFormatter setDateFormat:@"EEEE d MMMM"];
[_iconDateFormatter setDateFormat:[NSDateFormatter dateFormatFromTemplate:@"EEEE d MMMM" options:0 locale:[NSLocale currentLocale]]];
iconText = [_iconDateFormatter stringFromDate:[NSDate date]];
NSLog(@"%@",iconText);
图标文字的输出
4月23日 周二
但是我想要的是这样的周二 23日4月
非常感谢任何帮助。
问题是您正在调用 dateFormatFromTemplate
来生成您的格式。这 不会 为您提供您指定的确切格式;它更改格式以响应设备上的本地化设置。
如果您想完全控制格式,只需直接设置 dateFormat
明确的格式即可。
我在中文语言中遇到日期格式问题我想显示工作日月份但得到的输出为月份日工作日下面是我使用的代码
_iconDateFormatter.locale = NSLocale.currentLocale;
[_iconDateFormatter setDateFormat:@"EEEE d MMMM"];
[_iconDateFormatter setDateFormat:[NSDateFormatter dateFormatFromTemplate:@"EEEE d MMMM" options:0 locale:[NSLocale currentLocale]]];
iconText = [_iconDateFormatter stringFromDate:[NSDate date]];
NSLog(@"%@",iconText);
图标文字的输出
4月23日 周二
但是我想要的是这样的周二 23日4月
非常感谢任何帮助。
问题是您正在调用 dateFormatFromTemplate
来生成您的格式。这 不会 为您提供您指定的确切格式;它更改格式以响应设备上的本地化设置。
如果您想完全控制格式,只需直接设置 dateFormat
明确的格式即可。