开发者

if NSDate is Monday

开发者 https://www.devze.com 2023-01-03 06:15 出处:网络
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):

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

精彩评论

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