美文网首页
获取今天是星期几

获取今天是星期几

作者: MrCSA | 来源:发表于2017-09-12 10:40 被阅读0次

    + (NSString *) getweekDayStringWithDate:(NSDate *) date

    {

    NSCalendar * calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; // 指定日历的算法

    NSDateComponents *comps = [calendar components:NSWeekdayCalendarUnit fromDate:date];

    // 1 是周日,2是周一 3.以此类推

    NSNumber * weekNumber = @([comps weekday]);

    NSInteger weekInt = [weekNumber integerValue];

    NSString *weekDayString = @"(周一)";

    switch (weekInt) {

    case 1:

    {

    weekDayString = @"(周日)";

    }

    break;

    case 2:

    {

    weekDayString = @"(周一)";

    }

    break;

    case 3:

    {

    weekDayString = @"(周二)";

    }

    break;

    case 4:

    {

    weekDayString = @"(周三)";

    }

    break;

    case 5:

    {

    weekDayString = @"(周四)";

    }

    break;

    case 6:

    {

    weekDayString = @"(周五)";

    }

    break;

    case 7:

    {

    weekDayString = @"(周六)";

    }

    break;

    default:

    break;

    }

    return weekDayString;

    }

    相关文章

      网友评论

          本文标题:获取今天是星期几

          本文链接:https://www.haomeiwen.com/subject/bnxcsxtx.html