JSON Scraping - Convert military time to standard time via Javascript

后端 未结 5 1955
终归单人心
终归单人心 2021-01-18 19:41

I am scraping JSON data from a url. The time is military time and I was wondering if there is a way once I retrieve on the client side to convert it to standard time.

<
5条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-18 20:07

    DEMO

    window.onload=function() {
    
      var re=/(\d{2}:\d{2}[ap])/gi
      var times = document.getElementById('times').innerHTML;
      var mil = times.match(re);
      for (var i=0;i 12) parts[0]=hours-=12;
        else if (hours==0) parts[0]=12
        times=times.replace(mil[i],parts.join(":"))
      }
      document.getElementById('times').innerHTML = times;
    }
    

提交回复
热议问题