This commit is contained in:
2025-04-30 16:34:02 +08:00
parent dd5cf8ad36
commit 32258f688e
11 changed files with 85 additions and 16 deletions

View File

@@ -39,12 +39,35 @@
self.widthConstraint.constant = width+10;
self.dateLabel.text = self.list.createTime;
self.titleLabel.text = self.list.title;
double minutesDiff = [self minutesDifferenceFromTimeString:self.list.createTime withFormat:@"yyyy-MM-dd HH:mm:ss"];
[self.pvLab setTitle:[NSString stringWithFormat:@" %.0f",1000+minutesDiff] forState:0];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
//
- (double)minutesDifferenceFromTimeString:(NSString *)timeString withFormat:(NSString *)dateFormat {
// 1.
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:dateFormat]; // : @"yyyy-MM-dd HH:mm:ss"
// 2. NSDate
NSDate *targetDate = [dateFormatter dateFromString:timeString];
if (!targetDate) {
NSLog(@"时间字符串格式错误!");
return 0;
}
// 3.
NSDate *currentDate = [NSDate date];
// 4.
NSTimeInterval timeInterval = [currentDate timeIntervalSinceDate:targetDate];
// 5.
double minutes = fabs(timeInterval / 60.0);
return minutes;
}
@end