如何在用户的语言环境中获取星期几的名称? [英] How do I get the name of a day of the week in the user's locale?

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

问题描述

我有一个介于 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天全站免登陆