messageTime method
Implementation
String messageTime() {
if (this == null) return '';
// 当前时间
int time = (DateTime.now().millisecondsSinceEpoch / 1000).round();
int timeStamp = (this!.millisecondsSinceEpoch / 1000).round();
// 对比
int distance = time - timeStamp;
if (distance <= 60) {
return 'just now';
} else if (distance <= 3600) {
return '${(distance / 60).floor()} minutes ago';
} else if (distance <= 43200) {
return '${(distance / 60 / 60).floor()} hour ago';
} else if (DateTime.fromMillisecondsSinceEpoch(time * 1000).year ==
DateTime.fromMillisecondsSinceEpoch(timeStamp * 1000).year) {
return _CustomStamp_str(Timestamp: timeStamp, Date: 'MM/DD hh:mm', toInt: false);
} else {
return _CustomStamp_str(Timestamp: timeStamp, Date: 'YY/MM/DD hh:mm', toInt: false);
}
}