呆呆陈

博客园 首页 新随笔 联系 订阅 管理

 

 日期转星期几

   NSArray *arrWeek=[NSArray arrayWithObjects:@"周日", @"周一", @"周二", @"周三", @"周四", @"周五", @"周六", nil];

    NSDate *date = [NSDate date];

    NSCalendar *calendar = [ [NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];

    NSDateComponents *comps = [[NSDateComponents alloc] init];

    NSInteger unitFlags = NSYearCalendarUnit |

    NSMonthCalendarUnit |

    NSDayCalendarUnit |

    NSWeekdayCalendarUnit |

    NSHourCalendarUnit |

    NSMinuteCalendarUnit |

    NSSecondCalendarUnit;

    comps = [calendar components:unitFlags fromDate:date];

    int week = [comps weekday];

    int a = week - 1;

    NSString *weekStr = [NSString stringWithFormat:@"%@",[arrWeek objectAtIndex:a]];

    NSLog(@"啦啦啦 %@",weekStr);

   

posted on 2016-12-23 09:20  我是一只萌妹子  阅读(122)  评论(0编辑  收藏  举报