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

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -