JSON Scraping - Convert military time to standard time via Javascript

后端 未结 5 2000
终归单人心
终归单人心 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:25

    If you want to use the html, not the json, you can do this.

    dateEl.innerHTML=dateEl.innerHTML.replace(/(\d\d)(:\d\d[ap])/g,function(m,hour,suffix) {
      return (+hour+11)%12+1+suffix;
    });
    

    Note that this assumes you've set dateEl to the appropriate element, and that that element does not contain other times that you don't want to convert.

提交回复
热议问题