0

How I would go about displaying the time in a certain format (h:mm:ss a)? I can find examples for (hh:mm:ss a).

E.g of (h:mm:ss a) 9:10:23 PM

E.g of (hh:mm:ss a) 09:10:23 PM

EDIT: I achieved this my question with the following:

<i>var formatTime = (function () {

    return function (dt) {
        var formatted = '';

        if (dt) {
            var hours24 = dt.getHours();
            var hours = ((hours24 + 11) % 12) + 1;
            formatted = [formatted, [hours, addZero(dt.getMinutes())].join(":"), hours24 > 11 ? "PM" : "AM"].join(" ");            
        }

        return formatted;
    }
})();

alert(formatTime(new Date())); </i>
Vega
  • 27,856
  • 27
  • 95
  • 103
Z-Dog
  • 171
  • 1
  • 8
  • By using a time/date library. Or, take the example you found and modify it. –  Oct 01 '17 at 10:42
  • Or use library routines such as `toLocaleDateString()`, or `Intl.DateTimeFormat`. –  Oct 01 '17 at 10:49

0 Answers0