View difference between Paste ID: WBwL0qjJ and QA9DxNQe
SHOW: | | - or go back to the newest paste.
1
  /*
2
  <table>
3
    <td id="relogio" data-server-time="<?php echo date('Y,m,d,H,i,s'); ?>"></td>
4
  </table>
5
  */
6
7
  let agoraValue = 0;
8-
  
8+
 
9
  const doDom = () => {
10
    const relogio = document.querySelector("#relogio");
11
    const b = relogio.getAttribute("data-server-time").split(",");
12
    const agora = new Date(b[0], (b[1]-1), b[2], b[3], b[4], b[5]);
13-
    agoraValue = (agora.valueOf());
13+
    agoraValue = agora.valueOf();
14
    setInterval(iniciaCronometro,1000);
15
  };
16
     
17
  const iniciaCronometro = () => {
18
    const myDate = new Date(agoraValue);
19
    const h = myDate.getHours();
20
    const i = ("0" + String(myDate.getMinutes())).slice(-2);
21
    relogio.innerHTML = h+':'+i;
22-
    agoraValue = (myDate.valueOf()+1000);
22+
    agoraValue = agoraValue + 1000;
23-
    agoraValue = (timeAgora + 1);
23+
24-
  }
24+
25
  // Await DOM to be loaded
26
  if (document.readyState === 'loading') {
27
    document.addEventListener('DOMContentLoaded', () => {
28
      doDom();
29
    });
30
  } else {
31
    doDom();
32
  }