title: how to save time from javascript countdown timer value when form is opened?
body: <p>I have an online exam test project with countdown timer. I have start time (when form is opened) and end time(when we click submit button). My problem is, i can't save start time to database. How to solve it?</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>&lt;script type="text/javascript"&gt;
   var hoursleft = 0;
   /*get value from database*/
   var minutesleft = &lt;?php echo $menit-&gt;alat_waktu ?&gt;;
   var secondsleft = 0; 
   var finishedtext = "SELESAI";
   var end1;
   if(localStorage.getItem("end1")) 
   {
    end1 = new Date(localStorage.getItem("end1"));
   }
   else 
   {
    end1 = new Date();
    end1.setHours(end1.getHours()+hoursleft);
    end1.setMinutes(end1.getMinutes()+minutesleft);
    end1.setSeconds(end1.getSeconds()+secondsleft);
   }
  
  var counter = function () {
   var now = new Date();
   var datediff = end1 - now;
  
   diff = new Date(datediff);
  
   var milliseconds = parseInt((diff%1000)/100)
      var sec = parseInt((diff/1000)%60)
      var mins = parseInt((diff/(1000*60))%60)
      var hours = parseInt((diff/(1000*60*60))%24);
   if(hours &lt; 10) {
    hours = "0" + hours;
   }
   if (mins &lt; 10) {
    mins = "0" + mins;
   }
   if (sec &lt; 10) {
    sec = "0" + sec;
   }     
   if(now &gt;= end1) {     
    clearTimeout(interval);
    localStorage.setItem("end1", null);
    localStorage.removeItem("end1");
    document.getElementById('divCounter').innerHTML = finishedtext;
    
    if(confirm("TIME OUT !!!"))
    clearInterval(counter);
    window.location.href= "http://localhost/psiko";
    document.getElementById('myform').submit();
   } else {
    var value = hours + ":" + mins + ":" + sec;
  /*--------save variable value to db----------*/ 
  /*save countdown timer when form is opened*/
   // document.myform.waktu_awal.value = end1;
  /*save countdown timer when submit button is clicked*/
    document.myform.waktu_akhir.value = value;
  /*------------------------------------------------*/
    localStorage.setItem("end1", end1);
    document.getElementById('divCounter').innerHTML = value; 
   }
  }
  
  var interval = setInterval(counter, 1000);
  &lt;/script&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>waktu_awal is start_time and waktu_akhir is end_time</p>