(IOS)时间戳转星期

作者: rightmost | 来源:发表于2018-12-26 17:14 被阅读0次

    +(NSString*)getWeekDay:(NSString*)currentStr

    {

        NSDateFormatter* dateFormat = [[NSDateFormatter alloc]init];

        [dateFormatsetDateFormat:@"yyyy-MM-dd"];

        NSDate*date =[dateFormatdateFromString:currentStr];

        NSArray*weekdays = [NSArray arrayWithObjects: [NSNull null],@"星期日",@"星期一",@"星期二",@"星期三",@"星期四",@"星期五",@"星期六",nil];

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

        NSTimeZone*timeZone = [[NSTimeZonealloc]initWithName:@"Asia/Shanghai"];

        [calendarsetTimeZone: timeZone];

        NSCalendarUnit calendarUnit =NSCalendarUnitWeekday;

        NSDateComponents*theComponents = [calendarcomponents:calendarUnitfromDate:date];

        return[weekdaysobjectAtIndex:theComponents.weekday];

    }

    相关文章

      网友评论

        本文标题:(IOS)时间戳转星期

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