getTimeAgoByMs static method
Implementation
static String getTimeAgoByMs(int milliSecond, {String languageCode = 'en'}) {
var dateTime = DateTime.fromMillisecondsSinceEpoch(milliSecond);
final difference = DateTime.now().difference(dateTime);
if (difference.inMinutes < 3) {
return languageCode == "zh" ? "刚刚" : "just now";
} else if (difference.inMinutes < 60) {
return "${difference.inMinutes}${languageCode == "zh" ? "分钟前" : "minutes ago"}";
} else if (difference.inHours < 24) {
return "${(difference.inHours).toInt()}${languageCode == "zh" ? "小时前" : "hours ago"}";
} else if (difference.inDays < 365) {
return "${(difference.inDays).toInt()}${languageCode == "zh" ? "天前" : "days ago"}";
} else {
return "${difference.inDays ~/ 365}${languageCode == "zh" ? "年前" : "years ago"}";
}
}