Advertisement
Guest User

format_time_short

a guest
Dec 16th, 2020
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $(function() {
  2. window.format_time_short = function(seconds) {
  3.     var secondsPerMinute = 60;
  4.     var secondsPerHour = 3600;
  5.     var secondsPerDay = 86400;
  6.     var txt = "";
  7.     seconds = Math.round(seconds);
  8.     if (seconds < 120) {
  9.         var _minutes = Math.floor(seconds / secondsPerMinute);
  10.         if (_minutes) {
  11.             txt += _minutes + GT.time.m;
  12.             txt += " ";
  13.             seconds -= _minutes * secondsPerMinute;
  14.         }
  15.         txt += seconds < 10 ? "0" + seconds : seconds;
  16.         return txt + GT.time.s;
  17.     }
  18.     var days = Math.floor(seconds / secondsPerDay);
  19.     if (days) {
  20.         txt += days + GT.time.d;
  21.         seconds -= days * secondsPerDay;
  22.     }
  23.     var hours = Math.floor(seconds / secondsPerHour);
  24.     if (hours) {
  25.         if (days)
  26.             txt += " ";
  27.         txt += hours + GT.time.h;
  28.         seconds -= hours * secondsPerHour;
  29.     }
  30.     var minutes = Math.floor(seconds / secondsPerMinute);
  31.     if (minutes) {
  32.         if (hours)
  33.             txt += " ";
  34.         txt += minutes + GT.time.m;
  35.     }
  36.     return txt;
  37. };});
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement