开发者

if NSDate is Monday

How can I check if an NSDate开发者_开发百科 is a specific day of the week, like a Monday, Tuesday, Wednesday, and so on?


From memory (I don't have an ObjC environment handy at the moment):

int yourDOW = [[[NSCalendar currentCalendar] components:NSWeekdayCalendarUnit
    fromDate:yourDate] weekday];
if (yourDOW == 2) { ... }     // Sun = 1, Sat = 7

In other words:

  • Get the user's current calendar.
  • Get the weekday unit based on the given date.
  • Get the week day from that.
  • Compare it with what you want.
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜