How to get AM or PM?

后端 未结 11 1241
伪装坚强ぢ
伪装坚强ぢ 2020-12-08 19:38

I have buttons with the names of big cities.
Clicking them, I want to get local time in them.

$(\'#btnToronto\').click(function () {
    var hours = ne         


        
11条回答
  •  既然无缘
    2020-12-08 20:06

    You can use like this,

    var dt = new Date();
        var h =  dt.getHours(), m = dt.getMinutes();
        var _time = (h > 12) ? (h-12 + ':' + m +' PM') : (h + ':' + m +' AM');
    

    Hopes this will be better with minutes too.

提交回复
热议问题