Display countdown timer until given date using JavaScript from PHP

This function is used in my custom computer exam software to display a countdown timer that stops at the end of the exam. The timestamp is determined and stored in a file when the student clicks „begin exam”1) then it is resilient to page reloads since the destination timestamp never changes. Of course the timer is not exact since network latency is not taken into account, but this code is only used on a LAN 8-)

function jscd($ts) {
  $curts=time();
  $res="";
  $res.="<span id=cd></span>";
  $res.="<SCRIPT type='text/javascript' language='javascript'>
    var dst=(new Date().getTime()/1000) + $ts-$curts;
    function pitty() {
      var t=new Date().getTime()/1000;
      var diff=Math.floor(dst - t);
      var min=Math.floor(diff/60);
      var sec=diff%60;
      if(diff<0) {
        document.getElementById('cd').innerHTML = 'Lejárt az idő';
      } else {
        document.getElementById('cd').innerHTML = 'Hátralevő idő: ' + min + ' perc ' + sec + ' másodperc';
      }
      setTimeout('pitty()',100);
    }
    setTimeout('pitty()',100);";
  $res.="</SCRIPT>";
  return $res;
}
1)
code not included here