iOS 一句话获取日期和星期几

UILabel *dateLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 40)];

dateLabel.textAlignment = NSTextAlignmentCenter;

NSArray *dateArr = [_diffrentDateArr[section] componentsSeparatedByString:@"/"];

NSString *todayStr = [NSString string];

NSDate *todayDate = [NSDate date];

MyNSDateFormatter *dateFormatter = [[MyNSDateFormatter alloc]init];

[dateFormatter setDateFormat:@"yyyy/M/dd/EEEE"];

NSString *strDate = [dateFormatter stringFromDate:todayDate];

if([_diffrentDateArr[section] isEqualToString:strDate]){

todayStr = @"今天";

}else{

todayStr = @"";

}

dateLabel.text = [NSString stringWithFormat:@"%@ %@月%ld日 %@",todayStr,dateArr[1],[dateArr[2] integerValue],dateArr[3]];

 

posted @ 2019-03-14 21:57  Love margin  阅读(169)  评论(0编辑  收藏  举报