如何使用Cocoa查找任何给定日期的星期几

问题描述:

我想知道任何给定日期(即2009年6月27日)的日期(即星期一,星期五...)

I'm trying to figure out what day (i.e. Monday, Friday...) of any given date (i.e. Jun 27th, 2009)

谢谢。

我一直在做:

NSDateFormatter* theDateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[theDateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4];
[theDateFormatter setDateFormat:@"EEEE"];
NSString *weekDay =  [theDateFormatter stringFromDate:[NSDate date]];

这里有额外的好处,让您选择如何退还工作日更改setDateFormat中的日期格式字符串:call

This has the added bonus of letting you choose how you'd like the weekday to be returned (by changing the date format string in the setDateFormat: call

获取更多信息:

http://developer.apple.com /documentation/Cocoa/Conceptual/DataFormatting/Articles/dfDateFormatting10_4.html#//apple_ref/doc/uid/TP40002369