php date into javascript -
i have php date:
<?php date_default_timezone_set('europe/london'); echo date('d m d y h:i:s o'); ?> and javascript/jquery script publish date on website:
setinterval(function() { var d = new date("<? echo date('d m d y h:i:s o'); ?>") currenthours = d.gethours(); currenthours = ("0" + currenthours).slice(-2); currentminutes = d.getminutes(); currentminutes = ("0" + currentminutes).slice(-2); currentsec = d.getseconds(); currentsec = ("0" + currentsec).slice(-2); $('#timer').text((currenthours +':' + currentminutes + ':' + currentsec )); }, but javascript return an:an:an how insert server time javascript?
you can use new date() as
<script> function myfunction(obj) { var today = new date("<?php echo date('y-m-d h:i:s')?>"); var hh = today.gethours(); var ii = today.getminutes(); var ss = today.getseconds(); if (hh < 10) { hh = '0' + hh } if (ii < 10) { ii = '0' + ii } if (ss < 10) { ss = '0' + ss } obj.value = hh + ':' + ii + ':' + ss; } </script> <input type="text" onclick="myfunction(this);">
Comments
Post a Comment