ios - 我如何通过 Foundation 获取星期几?

如何以字符串形式获取星期几?

最佳答案

NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];  
[dateFormatter setDateFormat:@"EEEE"];
NSLog(@"%@", [dateFormatter stringFromDate:[NSDate date]]);

根据当前区域设置将当前星期几输出为区域设置中的字符串。

要获得工作日编号,您必须使用 NSCalendar 类:

NSCalendar *gregorian = [[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar] autorelease];
NSDateComponents *comps = [gregorian components:NSWeekdayCalendarUnit fromDate:[NSDate date]];
int weekday = [comps weekday];

https://stackoverflow.com/questions/4269093/

相关文章:

ios - UIAlertController 自定义字体、大小、颜色

objective-c - 检查方法是否存在

objective-c - iOS 应用程序 : how to clear notification

iphone - 如何制作 URL/电话可点击的 UILabel?

objective-c - 在 Objective-C 中获取对象属性列表

ios - 在输入击键时获取 UITextField 的值?

c++ - 从 C++ 成员函数调用 Objective-C 方法?

iphone - 使用 Core Data 实现枚举的最佳方法

ios - 使用自动布局在 UICollectionView 中指定单元格的一维

ios - 了解 ibecon 距离