How to get AM or PM?

后端 未结 11 1248
伪装坚强ぢ
伪装坚强ぢ 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:15

    var now = new Date();
    var hours = now.getHours();
    var minutes = now.getMinutes();
    var ampm = hours >= 12 ? 'pm' : 'am';
    hours = hours % 12;
    hours = hours ? hours : 12;
    minutes = minutes < 10 ? '0' + minutes : minutes;
    var timewithampm = hours + ':' + minutes + ' ' + ampm;
    return timewithampm;
    

提交回复
热议问题