Skip to content

Instantly share code, notes, and snippets.

@hjst
Last active November 21, 2018 05:22

Revisions

  1. hjst revised this gist Jan 27, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    function format_time(date_obj) {
    // formats a javascript Date object into a 12h am/pm time string
    // formats a javascript Date object into a 12h AM/PM time string
    var hour = date_obj.getHours();
    var minute = date_obj.getMinutes();
    var amPM = (hour > 11) ? "pm" : "am";
  2. hjst renamed this gist Oct 31, 2011. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. hjst created this gist Oct 31, 2011.
    15 changes: 15 additions & 0 deletions plugins
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    function format_time(date_obj) {
    // formats a javascript Date object into a 12h am/pm time string
    var hour = date_obj.getHours();
    var minute = date_obj.getMinutes();
    var amPM = (hour > 11) ? "pm" : "am";
    if(hour > 12) {
    hour -= 12;
    } else if(hour == 0) {
    hour = "12";
    }
    if(minute < 10) {
    minute = "0" + minute;
    }
    return hour + ":" + minute + amPM;
    }