How to get AM or PM?

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

    very interesting post. in a function that take a date in parameter it can appear like that :

    function hourwithAMPM(dateInput) {
       var d = new Date(dateInput);
       var ampm = (d.getHours() >= 12) ? "PM" : "AM";
       var hours = (d.getHours() >= 12) ? d.getHours()-12 : d.getHours();
    
       return hours+' : '+d.getMinutes()+' '+ampm;
    
    }
    

提交回复
热议问题