开发者

How to obtain a localized string representation of the weekdays like monday, tuesday, etc.?

开发者 https://www.devze.com 2023-01-06 12:43 出处:网络
How to obtain a localized string representation of the weekdays like monday, tuesday, etc.? Sure I c开发者_如何学编程ould localize these myself but I bet that I can suck them out from a calendar clas

How to obtain a localized string representation of the weekdays like monday, tuesday, etc.?

Sure I c开发者_如何学编程ould localize these myself but I bet that I can suck them out from a calendar class or something similar?


This is what you want:

NSArray *weekdays = [[[NSDateFormatter alloc] init] weekdaySymbols];
NSLog(@"%@", weekdays);

Output:

(
    Sunday,
    Monday,
    Tuesday,
    Wednesday,
    Thursday,
    Friday,
    Saturday
)

Enjoy!


Given a valid NSDate, NSDateFormatter can output the name of the weekday with the date format @"EEEE". I don't know of a simpler way to do this in Cocoa.


Why don't you just use the monthSymbols array from NSDateFormatter?

0

精彩评论

暂无评论...
验证码 换一张
取 消