I need refresh my time zone every seconds.
I have this code:
$now = new DateTime(null, new DateTimeZone('America/New_York'));
$now->setTimezone(new DateTimeZone('Europe/London')); echo
$now->format("H:i:s A");
And I want to show time by time zone (state) on my server, with refresh.
Like this code but with my time zone state like Europe/London or other state:
<script type="text/javascript">
function display_c(){
var refresh=1000; // Refresh rate in milli seconds
mytime=setTimeout('display_ct()',refresh)
}
function display_ct() {
var strcount
var x = new Date()
document.getElementById('ct').innerHTML = x;
tt=display_c();
}
</script>
<body onload=display_ct();>
<span id='ct' ></span>
So is there code for JavaScript show DateTimeZone('America/New_York')
with refresh time?
example : http://www.thetimenow.com/canada
i found this var java script but its wrong can any one plz corecet this code
<script>
var server_name = "www.site.com";
var time_format = '24';
var timezones = ["America/Montreal","Etc/GMT+5","Etc/GMT+4","Etc/GMT+6","Etc/GMT+5","Etc/GMT+8","Etc/GMT+7","GMT","UTC"];
document.writeln(" $date = new DateTime($ref['lastupdated']); ");
document.writeln(" $date->setTimezone(new DateTimeZone('America/Los_Angeles')); ");
var current_time = {"America/Montreal":["<? print date("H", time())?>","<? print date("i", time())?>","<? print date("s", time())?>","<? print date("l", time())?>","<? print date("F", time())?>","<? print date("d", time())?>","<? print date("Y", time())?>"]]};
</script
the real code php is
<?Php
$date = new DateTime($ref['lastupdated']);
$date->setTimezone(new DateTimeZone('America/Los_Angeles'));
echo $date->format('m/d/y g:i:s a');
?>
update source in php
<?php
echo "<div id=\"output\"></div>";
echo "<script type='text/javascript'>
( function()
{
// use JavaScript Date to display current date
// in a div (#displayJsDate)
var output = document.getElementById('output');
var start = moment("<? print date("c")?>");
var delta = start - moment();
setInterval(function(){
var now = moment().add(delta,'ms');
var m = now.tz('$data[zone]'); // Set the time zone as desired
var s = m.format('YYYY-MM-DD h:mm:ss A');
output.innerHTML = s;
}, 1000);
})();
</script>";
?>