开发日记:时间线对比

开发日记:时间线对比

narakuyang
2021-12-25 / 0 评论 / 35 阅读 / 正在检测是否收录...
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;
}
0

评论

博主关闭了所有页面的评论