How to convert time from 24 hour format to 12 hour format using javascript?

后端 未结 5 1730
逝去的感伤
逝去的感伤 2021-01-03 00:55

The function returns the time in 24 hour format.

function fomartTimeShow(h) {
    return h < 10 ? \"0\" + h + \":00\" : h + \":00\";
}
5条回答
  •  忘掉有多难
    2021-01-03 01:27

    function fomartTimeShow(h) {
        var s = (h % 24 < 12) ? "am" : "pm", h = h % 12 || 12;
        return (h < 10 ? "0" + h : h)  + ":00" + " " + s;
    }
    

提交回复
热议问题