Clocks of different Time Zones


Timezones of the world
Select one time zone

Displaying changing clock with date for user selected time zone from a JavaScript dropdown list box

JavaScript function to generate the date and time of Timezone

<script>function disp_TZ(){
tz=f1.tz.options[f1.tz.options.selectedIndex].value;
str= new Date().toLocaleString("en-NZ", 
	{timeZone: tz,timeZoneName:"short"})
document.getElementById('ct').innerHTML = str + "," + tz;
display_c()
}
function display_c(){
var refresh=1000; // Refresh rate in milli seconds
mytime=setTimeout('disp_TZ()',refresh)
}
</script>
<span id='ct' style="background-color: #FFFF00">
Select one time zone </span>
Copy the List of JavaScript Array of Timezones

Hour Minutes and seconds part of time zone

<script>
function disp_TZ(){
  //tz='Africa/Accra'
tz=f1.tz.options[f1.tz.options.selectedIndex].value  
str=new Date().toLocaleString("en-NZ",
{timeZone:tz,timeZoneName:"short"})


document.getElementById('ct').innerHTML=str + " , "+tz  
// showing hour minutes and seconds ///
dt2 = new Date();
str2 = new Date(dt2.toLocaleString('en-US',{
    timeZone: tz}));

diff=dt2.getTime()-str2.getTime();	
dt3=new Date(dt2.getTime()-diff);
hour=dt3.getHours();
minute=dt3.getMinutes();
seconds=dt3.getSeconds();
str3= hour + ':' + minute + ':' + seconds 
document.getElementById('ct2').innerHTML= str3
////  end of hour minutes and seconds ///
display_c()
}
function display_c(){
refresh=1000
mytime=setTimeout('disp_TZ()',refresh)
}
var my_timezones=[
'Africa/Abidjan',
'Africa/Accra',
'Africa/Addis_Ababa'
]
for(i=0;i<my_timezones.length;i++){
  addOption(document.f1.tz,my_timezones[i],my_timezones[i])
}
function addOption(selectbox,text,value){
var optn=document.createElement("OPTION")
optn.text=text
optn.value=value
selectbox.options.add(optn)
}
</script>
The HTML part
<span id=ct>Timezone here </span><br>
<span id=ct2>Hour Minutes Sec here </span><br>
<input type=button value='Show' onClick=disp_TZ()>
<form name=f1>
<select name=tz onChange=disp_TZ()>
</select>
</form>
DEMO and copy the source code from here

PHP code to generate dropdown list with timezones

<form method=post name=f1>
<?Php
$a = timezone_identifiers_list();
echo "<select name=tz onChange=disp_TZ() class='form-control'>";
while (list ($key, $val) = each ($a)) {
//echo "$key -> $val <br>";
echo "<option value=$val>$val</option>";
} 
echo "</select>";
?>
</form>

PHP code to generate JavaScript array with timezones list

<?Php 
$str= "<script>";
$str.="var my_timezones=[\n";
$a=timezone_identifiers_list(); 
while (list($key,$val) = each ($a)) {
$str.="'".$val."',\n";
}
$str.="]\n
</script>";
echo $str;
?>
Copy the List of JavaScript Array of Timezones

Read more on timezone_identifiers_list() function in PHP


Using offset from current date and time ( old script )
<script type="text/javascript"> 
var day_name=new Array(7);

day_name[0]='Sunday'
day_name[1]=' Monday'
day_name[2]='Tuesday'
day_name[3]='Wednesday'
day_name[4]='Thursday'
day_name[5]='Friday'
day_name[6]='Saturday'

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;
var x1=x.toUTCString();// changing the display to UTC string
var gmt=new Date();
var offSet=x.getTimezoneOffset(); 
gmt.setMinutes(x.getMinutes()+offSet);
document.getElementById('ct1').innerHTML = gmt.getHours() + ":" +gmt.getMinutes() + ":" + gmt.getSeconds();

//////////////////////////
function city_zone(offSet){
var t1=new Date();
var offSet1=t1.getTimezoneOffset(); 
t1.setMinutes(t1.getMinutes()+offSet1); // arrive at GMT tme
t1.setMinutes(t1.getMinutes()+offSet);   // add the city time offset 
var str=t1.getMonth() + 1;  
return t1.getHours() + ":" +t1.getMinutes() + ":" + t1.getSeconds() + " <i>Day:</i> "  + day_name[t1.getDay()] + ", <i>Date :</i> " + t1.getDate() + " <i>Month :</i> " +  str;
}
//////////////////

// Go for different City time ///

document.getElementById('ct2').innerHTML = city_zone(-420); // Arizona 
document.getElementById('ct3').innerHTML = city_zone(-480); // California
document.getElementById('ct4').innerHTML = city_zone(600); // New South Wales


tt=display_c();
}
</script>
HTML part
<table class='table table-striped'>  
<tr class='info'><td>Area </td><td>Time</td><td>Time Off Set </td></tr>
<tr class='danger'><td>Local </td><td colspan=2><span id='ct' ></span></td></tr>
<tr class='success'><td>GMT </td><td><span id='ct1' ></span></td><td></td></tr>
<tr><td>Arizona </td><td><span id='ct2' ></span></td><td>-7 Hrs</td></tr>
<tr><td>Carlifornia </td><td><span id='ct3' ></span></td><td>-8 Hrs</td></tr>
<tr><td>New South Wales</td><td><span id='ct4' ></span><td>10 Hrs</td></td></tr>
</table>
Date Reference Showing Changing Clock

Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com







    Post your comments , suggestion , error , requirements etc here




    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2021 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer