getTimeDuration static method
Implementation
static String getTimeDuration(String comTime) {
var nowTime = DateTime.now();
var compareTime = DateTime.parse(comTime);
if (nowTime.isAfter(compareTime)) {
if (nowTime.year == compareTime.year) {
if (nowTime.month == compareTime.month) {
if (nowTime.day == compareTime.day) {
// if (nowTime.hour == compareTime.hour) {
// if (nowTime.minute == compareTime.minute) {
//
return '${compareTime.hour}:${(compareTime.minute < 10) ? '0${compareTime.minute}' : compareTime.minute.toString()}';
// }
// return (nowTime.minute - compareTime.minute).toString() + '分钟前';
// }
// return (nowTime.hour - compareTime.hour).toString() + '小时前';
}
return '${nowTime.day - compareTime.day}天前';
}
return '${nowTime.month - compareTime.month}月前';
}
return '${nowTime.year - compareTime.year}年前';
}
return 'time error';
}