How to get AM or PM?

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

    Try below code:

    $('#btnToronto').click(function () {
        var hours = new Date().getHours();
        var hours = (hours+24-2)%24; 
        var mid='am';
        if(hours==0){ //At 00 hours we need to show 12 am
        hours=12;
        }
        else if(hours>12)
        {
        hours=hours%12;
        mid='pm';
        }
        alert ('Toronto time: ' + hours + mid);
    });
    

提交回复
热议问题