title: How to get users pc time using php
body: <p>I am working on an application in which I need to get date &amp; time of local pc of user. Basically php have date and time functions and it returns server time as it is server side scripting language. </p>
  
  <p>I am getting correct time using javascript <strong>Date</strong> function but when i use <strong>strtotime</strong> function in php it doesn't work, i need a way to get local time in php.</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  
  function getDate() 
  { 
          var d = new Date();
      var c_day = d.getDate();
      var c_month = d.getMonth() + 1;
      var c_year = d.getFullYear();
      var c_hour = d.getHours(); 
      var c_min = d.getMinutes(); 
      var t = c_day+"-"+c_month+"-"+c_year+" "+c_hour+":"+c_min;
      return t;
  }
  if (window.XMLHttpRequest)
  {
      xmlhttp=new XMLHttpRequest();
  }
  else
  {
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  xmlhttp.onreadystatechange=function()
  {
      if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200)
      { 
          alert(xmlhttp.responseText);        
      }
  }    
  xmlhttp.open("GET","setdate.php?sdate="+encodeURIComponent(getDate()),false);
  xmlhttp.send();
  &lt;/script&gt;
  </code></pre>
  
  <p>The file 'setdate.php' stores sdate value in the session and i am getting it as an output of ajax.</p>
  
  <pre><code>&lt;?php
  $sdate = $_SESSION['sdate'];
  $date = date( "d/m/Y", strtotime( $sdate ) );
  ?&gt;
  </code></pre>
  
  <p>This works after refreshing the page, but not when the page loads first time.</p>
  
  <p>Any one can help me on this ?</p>