如何获取用户区域设置中的星期几的名称? [英] How do I get the name of a day of the week in the user's locale?

查看:138
本文介绍了如何获取用户区域设置中的星期几的名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个介于1和7之间的数字,我想转换成用户的区域设置相当于星期一到星期日。

I have a number between 1 and 7, which I want to turn into the user's locale's equivalent of Monday to Sunday. Can I do that and if so, how?

推荐答案

NSDateFormatter 可以给出名称列表:

An NSDateFormatter can give you the list of names:

NSDateFormatter * df = [[NSDateFormatter alloc] init];
[df setLocale: [NSLocale currentLocale]];
NSArray * weekdays = [df weekdaySymbols];

然后可以像任何其他数组一样索引 [weekdays objectAtIndex:dayIdx] ; 但请注意,第一个工作日可能因地区而异; (和 NSCalendar 的许多其他方面)在文档中没有特别说明。

Which you can then index like any other array [weekdays objectAtIndex:dayIdx]; Be aware, however, that the first weekday may differ by locale; exactly how it may vary (along with many other things about NSCalendar) is not particularly well-explained in the docs.

这篇关于如何获取用户区域设置中的星期几的名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆