seconds to string like '30m 40s' and '1d 20h 30m 40s'

@param secs
@return
762883
public static String prettyUptime(int secs) {
        String[][] PRETTYSECDIVIDERS = { new String[] { "s", "60" }, new String[] { "m", "60" }, new String[] { "h", "24" },
                new String[] { "d", null } };
        int diversize = PRETTYSECDIVIDERS.length;

        LinkedList<String> tmp = new LinkedList<>();
        int div = secs;
        for (int i = 0; i < diversize; i++) {
            if (PRETTYSECDIVIDERS[i][1] != null) {
                Integer d = Integer.parseInt(PRETTYSECDIVIDERS[i][1]);
                tmp.addFirst(div % d + PRETTYSECDIVIDERS[i][0]);
                div = div / d;
            } else {
                tmp.addFirst(div + PRETTYSECDIVIDERS[i][0]);
            }
            if (div <= 0 ) break;
        }

        Joiner joiner = Joiner.on(" ");
        return joiner.join(tmp);
    }
1201963
public static String convertMsToShortClockTime(long millis) {
    Preconditions.checkArgument(millis >= 0, "Negative values are not supported");

    long days = millis / Constants.DAY_MS;
    long hours = (millis % Constants.DAY_MS) / Constants.HOUR_MS;
    long mins = (millis % Constants.HOUR_MS) / Constants.MINUTE_MS;
    long secs = (millis % Constants.MINUTE_MS) / Constants.SECOND_MS;

    return String.format("%d d, %d h, %d m, and %d s", days, hours, mins, secs);
  }
1202445
public static String milliSecToString(final long mS) {
    final long rem_mS = (long)(mS % 1000.0);
    final long rem_sec = (long)((mS / 1000.0) % 60.0);
    final long rem_min = (long)((mS / 60000.0) % 60.0);
    final long hr  =     (long)(mS / 3600000.0);
    final String mSstr = zeroPad(Long.toString(rem_mS), 3);
    final String secStr = zeroPad(Long.toString(rem_sec), 2);
    final String minStr = zeroPad(Long.toString(rem_min), 2);
    return String.format("%d:%2s:%2s.%3s", hr, minStr, secStr, mSstr);
  }
1269719
public static String format(long elapsedNs) {
    if (elapsedNs >= ONE_HOUR) {
      long hours = elapsedNs / ONE_HOUR;
      long minutes = (elapsedNs % ONE_HOUR) / ONE_MINUTE;
      return hours + " h " + minutes + " mn";
    } else if (elapsedNs >= ONE_MINUTE) {
      long minutes = elapsedNs / ONE_MINUTE;
      long seconds = (elapsedNs % ONE_MINUTE) / ONE_SECOND;
      return minutes + " mn " + seconds + " s";
    } else if (elapsedNs >= ONE_SECOND) {
      long seconds = elapsedNs / ONE_SECOND;
      long milliseconds = (elapsedNs % ONE_SECOND) / ONE_MILLISECOND;
      return seconds + "." + milliseconds + " s";
    } else if (elapsedNs >= ONE_MILLISECOND) {
      return (elapsedNs / ONE_MILLISECOND) + " ms";
    } else if (elapsedNs >= ONE_MICROSECOND) {
      return (elapsedNs / ONE_MICROSECOND) + " us";
    } else {
      return elapsedNs + " ns";
    }
  }
898718
function(ms) {
      var sec = 1000;
      var min = 60 * 1000;
      var hour = 60 * min;

      if (ms >= hour) {
        return (ms / hour).toFixed(1) + 'h';
      }
      if (ms >= min) {
        return (ms / min).toFixed(1) + 'm';
      }
      if (ms >= sec) {
        return (ms / sec | 0) + 's';
      }
      return ms + 'ms';
    }
801444
def format_time_small(seconds):
    

    if not isinstance(seconds, (int, float)):
        return str(seconds)

    if math.isnan(seconds):
        return "-"

    if abs(seconds)<1:
        milliseconds = 1000*seconds
        if abs(milliseconds)<1:
            microseconds = 1000*milliseconds
            if abs(microseconds)<1:
                nanoseconds = 1000*microseconds
                if abs(nanoseconds)<0.5:
                    return "0"
                else:
                    return "{:.0f}ns".format(nanoseconds)
            elif abs(microseconds)<10:
                return "{:.2f}us".format(microseconds)
            elif abs(microseconds)<100:
                return "{:.1f}us".format(microseconds)
            else:
                return "{:.0f}us".format(microseconds)
        elif abs(milliseconds)<10:
            return "{:.2f}ms".format(milliseconds)
        elif abs(milliseconds)<100:
            return "{:.1f}ms".format(milliseconds)
        else:
            return "{:.0f}ms".format(milliseconds)
    elif abs(seconds)<10:
            return "{:.2f}s".format(seconds)
    elif abs(seconds)<100:
        return "{:.1f}s".format(seconds)
    else:
        return "{:.0f}s".format(seconds)
774216
final public static function secondsToSpec($secs)
    {
        if (!empty($secs)) {
            try {
                $interval = self::secondsToInterval($secs);
                return self::intervalToSpec($interval);
            } catch (\Exception $e) {
            }
        }

        return "";
    }
1185328
public static function timestampToSeconds($string)
    {
        // Extract hour, minute, and seconds
        $time = explode(":", $string);
        
        // Convert to seconds (round up to nearest second)
        $secs = ($time[0] * 3600) + ($time[1] * 60) + (ceil($time[2]));
        return $secs;
    }
491124
public static String[] getHourMinuteSecondTimeString(long time) {

        int hours = (int)time / (1000 * 60 * 60);
        int min = (int)(time - (hours * 1000 * 60 * 60)) / (1000 * 60);
        int sec = (int)(time - (hours * 1000 * 60 * 60) - (min * 1000 * 60)) / 1000;

        return new String[] {getTwoDigitsString(hours), getTwoDigitsString(min), getTwoDigitsString(sec)};
    }
663642
private long parseDuration(String value) {
        long periodMS = 0L;
        if (Objects.nonNull(value)) {
            String[] parts = value.split(":");
            for (int i = 0; i < parts.length; i++) {
                switch (i) {
                    case 0: // hours
                        periodMS += (Integer.parseInt(parts[i])) * 3600000L;
                        break;
                    case 1: // minutes
                        periodMS += (Integer.parseInt(parts[i])) * 60000L;
                        break;
                    case 2: // seconds
                        periodMS += (Integer.parseInt(parts[i])) * 1000L;
                        break;
                    case 3: // ms
                        periodMS += (Integer.parseInt(parts[i]));
                        break;
                    default:
                        break;
                }
            }
        }
        return periodMS;
    }
903610
def seconds(value)
      result = if value >= 60 * 60
                 "#{value / 60 / 60}:#{Kernel.format('%02i', (value / 60) % 60)}"
               else
                 (value / 60).to_s
               end

      result + ':' + Kernel.format('%02i', value % 60)
    end
291549
function minutesToOffsetString(minutes) {
  var t = String(Math.abs(minutes / 60)).split('.');
  var H = pad(t[0]);
  var m = t[1] ? parseInt(t[1], 10) * 0.6 : 0;
  var sign = minutes < 0 ? '-' : '+';

  return '' + sign + H + ':' + pad(m);
}
1348198
def show_time_as_short_string(self, seconds):
        
        if seconds < 60:
            return str(seconds) + ' seconds'
        elif seconds < 3600:
            return str(round(seconds/60, 1)) + ' minutes'
        elif seconds < 3600*24:
            return str(round(seconds/(60*24), 1)) + ' hours'
        elif seconds < 3600*24*365:
            return str(round(seconds/(3600*24), 1)) + ' days'
        else:
            print('WARNING - this will take ' + str(seconds/(60*24*365)) + ' YEARS to run' )
            return str(round(seconds/(60*24*365), 1)) + ' years'
862547
private static String time2Str(long elapsedTime) {
    String unit;
    double time = elapsedTime;
    if (elapsedTime < 1000) {
      unit = "milliseconds";
    } else if (elapsedTime < 60*1000) {
      unit = "seconds";
      time = time/1000;
    } else if (elapsedTime < 3600*1000) {
      unit = "minutes";
      time = time/(60*1000);
    } else {
      unit = "hours";
      time = time/(3600*1000);
    }

    return time+" "+unit;
  }
823070
public static String formatDuration(long durationInMs) {
    if (durationInMs < 1000) {
      return String.format("%sms", durationInMs);
    } else {
      long sec = durationInMs / 1000;
      if (sec < 60) {
        return String.format("%ss", sec);
      } else {
        long min = sec / 60;
        long remainingSec = sec - (min * 60);
        if (remainingSec > 0) {
          return String.format("%smin %ss", min, remainingSec);
        } else {
          return String.format("%smin", min);
        }
      }
    }
  }
1342838
def seconds_to_hms_verbose(t):
    
    hours = int((t / 3600))
    mins = int((t / 60) % 60)
    secs = int(t % 60)
    return ' '.join([
        (hours + ' hour' + ('s' if hours > 1 else '')) if hours > 0 else '',
        (mins + ' minute' + ('s' if mins > 1 else '')) if mins > 0 else '',
        (secs + ' second' + ('s' if secs > 1 else '')) if secs > 0 else ''
    ])
938715
public static String getGMTTimeString(long milliSeconds) {
		SimpleDateFormat sdf = new SimpleDateFormat("E, d MMM yyyy HH:mm:ss 'GMT'", Locale.ENGLISH);
		return sdf.format(new Date(milliSeconds));
	}