修改
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user