Format Javascript Date object or Unix timestamp into a human-readable date

Here’s a compact little function that formats a Javascript Date object or a Unix timestamp into a human-readable date like 04/19/2012 07:16:15

function formatDate(d){
  if(typeof d === 'number') d = new Date(d);
  if(!(d instanceof Date)) return d;
  function pad(n){return n<10 ? '0'+n : n}
  return pad(d.getMonth()+1)+'/'
        + pad(d.getDate())+'/'
        + d.getFullYear()+" "
        + pad(d.getHours()) + ":"
        + pad(d.getMinutes()) + ":"
        + pad(d.getSeconds());
}