datesDiffen({
required String timeinfo,
}) {
String timeshow;
DateTime time =
DateTime.fromMillisecondsSinceEpoch(int.parse(timeinfo + '000'));
DateTime localtime = DateTime.now();
Duration difftime = localtime.difference(time);
int timeday = difftime.inDays;
int timehour = difftime.inHours;
int timemill = difftime.inMinutes;
int timesecd = difftime.inSeconds;
if (timeday > 0) {
timeshow = '$timeday天前';
} else if (timehour > 0) {
timeshow = '$timehour小时前';
} else if (timemill > 0) {
timeshow = '$timemill分前';
} else if (timesecd > 0) {
timeshow = '$timesecd秒前';
} else {
timeshow = '刚刚';
}
return timeshow;
}
版权属于:
narakuyang
作品采用:
《
署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)
》许可协议授权
评论