如何使用Cocoa查找任何给定日期的星期几 [英] How to find what day of the week for any given date using Cocoa

查看:126
本文介绍了如何使用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

这篇关于如何使用Cocoa查找任何给定日期的星期几的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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