Skip to content

Instantly share code, notes, and snippets.

@mikebobadilla
Created January 9, 2016 19:18
Show Gist options
  • Save mikebobadilla/6e8e56a07197acae9be1 to your computer and use it in GitHub Desktop.
Save mikebobadilla/6e8e56a07197acae9be1 to your computer and use it in GitHub Desktop.

Revisions

  1. mikebobadilla created this gist Jan 9, 2016.
    14 changes: 14 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    function formatDate(date) {
    var hours = date.getHours();
    var minutes = date.getMinutes();
    var ampm = hours >= 12 ? 'pm' : 'am';
    hours = hours % 12;
    hours = hours ? hours : 12; // the hour '0' should be '12'
    minutes = minutes < 10 ? '0'+minutes : minutes;
    var strTime = hours + ':' + minutes + ' ' + ampm;
    return date.getMonth()+1 + "/" + date.getDate() + "/" + date.getFullYear() + " " + strTime;
    }

    var d = new Date();
    var e = formatDate(d);
    alert(e);