Fnykis
6/7/2018 - 12:24 PM

Date fuser

Gets a sweet formatted date with a few options

function dateFuser(date, length, separator, useTime) {
  var y = date.getFullYear();
  var m = date.getMonth();
  var d = date.getDate();
  var min = date.getHours();
  var h = date.getMinutes();

  if (length == "short") y = String(y).substring(2,4);
  if (m < 10) m = "0" + m;
  if (d < 10) d = "0" + d;
  if (min < 10) min = "0" + min;
  if (h < 10) h = "0" + h;
  
  if (useTime) {
    return y + separator + m + separator + d + " " + h + ":" + min;
  } else {
    return y + separator + m + separator + d;
  }
}