getDurationFromHour static method

String getDurationFromHour(
  1. int sec
)

持续时间(h)

Implementation

static String getDurationFromHour(int sec) {
  var duration = Duration(seconds: sec);
  var microseconds = duration.inMicroseconds;
  if (microseconds < 0) {
    return '';
  }

  var hours = microseconds ~/ Duration.microsecondsPerHour;
  microseconds = microseconds.remainder(Duration.microsecondsPerHour);

  if (microseconds < 0) microseconds = -microseconds;

  var minutes = microseconds ~/ Duration.microsecondsPerMinute;
  microseconds = microseconds.remainder(Duration.microsecondsPerMinute);
  var seconds = microseconds ~/ Duration.microsecondsPerSecond;
  microseconds = microseconds.remainder(Duration.microsecondsPerSecond);
  return "${hours.abs() > 0 ? '${hours.abs()}小时' : ''}"
      "${minutes > 0 ? '$minutes分' : ''}"
      "${seconds > 0 ? '$seconds秒' : ''}";
}