Javascript Number toHMS()

Description

Javascript Number toHMS()

/**//from ww w . j  ava 2s.  c  o  m
 * Return Hour minute second from decimal hours
 *
 * @returns {*}
 */
Number.prototype.toHMS = function () {
    let hour, minute, second, f;

    hour   = parseInt(this);
    f      = this - hour;
    f      = f * 60;
    minute = parseInt(f);
    f      = f - parseInt(f);
    second = parseInt(f * 60);

    return `${hour}h ${minute}m ${second}s`;
};



PreviousNext

Related