× Warning! This forum is in archival status. New contributions may not work.
Time format to AM/PM
  • Does anyone know how to change the time format off the 24hr format and onto a standard AM/PM format?
  • 7 Comments sorted by
  • Vote Up0Vote Down Daniel JamesDaniel James
    Posts: 844Member, Sourcefabric Team
    Hi Jess, are you looking to change the calendar in the Airtime administration interface, or the widgets for public facing websites?

    Cheers!

    Daniel
  • Being able to change it in the admin interface would be nice!
  • Hey Daniel, both would be great.  The website widget for sure.
  • Easy to change it in the widget - its just a few lines.

    Post edited by John Chewter at 2014-06-28 05:08:39
    No longer using Airtime or Libretime.
  • Vote Up0Vote Down Daniel JamesDaniel James
    Posts: 844Member, Sourcefabric Team
    Hi John, please post your solution for the widget time format, I can then add it to the manual. Cheers! Daniel
  • /*
    Here is a small general 24hr ->12hr AM/PM function.
    Paste this function at the top of jquery.showinfo.js, just under the Airtime API version, or at the top of whatever javascript widget you are using. Use it wherever you need to change the time format.
    See it working here: http://www.deprogrammedradio.com/

    It takes standard javascript date objects. Usage example:
                        var SchedStartAMPM = formatTimeAMPM(SchedStartTime);
                        var SchedEndAMPM = formatTimeAMPM(SchedEndTime);

     */

    function formatTimeAMPM(date) {
        function pad(n) { return (n < 10) ? '0' + n : n; }
        var time = new Date(date);
        var hours = time.getHours();
        var minutes = time.getMinutes();
        var ext ='am';
        if (hours >= 12) {
            hours -= 12;
            ext ='pm';
        }
        if (hours === 0) { hours = 12; }
        return hours + ':' + pad(minutes) + ext;
    }


    Post edited by John Chewter at 2014-06-28 12:30:56
    No longer using Airtime or Libretime.
  • Any quick but clean fixes to change the web UI time to 12hr am/pm?