codeigniter - Time Difference between php and javascript -
here code :
function server_time() { $this->load->helper('date'); echo '<script>document.write((new date())); </script>'; echo '<br/>'; echo gmdate('d m d y g:i:s t', time()); }
output :
fri jun 19 2015 19:24:49 gmt+0530 (india standard time) fri jun 19 2015 14:02:44 gmt
how same result below.
you can server time when page loads, , count then:
function server_time() { $this->load->helper('date'); $sd = date('y, m, d, g, i, s, u'); echo '<script>var sd = new date(' . $sd . ');</script>'; }
your js have variable, sd
, set same time server. can manipulate other date object.
edit
if not working, go epoch.
function server_time() { $this->load->helper('date'); $ts = time(); echo '<script>var sd = new date(); sd.settime(' . $ts . ');</script>'; }
Comments
Post a Comment