Ejemplos en Javascript

Husos horarios, secondo esempio

10 husos horarios de 10 ciudades del mundo

<HTML>
<HEAD>

<TITLE>Ejemplos Javascript: ejemplo pr???¡ctico </TITLE>


</HEAD>

<BODY bgcolor="white">

<script language="javascript1.2">

<!-- hide it

// This is my first ever made-from-scratch JavaScript.  It probably shows.
// It reads local time of the client computer, translates it to GMT, then does
// the math to show the time in a few cities around the world.  Feel free
// to use it, and modify it as you see fit; but leave this disclaimer in-
// tact.  
//
// Only works on Communicator4, but should be gracefully ignored by lesser
// browsers.
//
// By using this JavaScript, you are acknowledging that the author,
// Stuart Price, can not be held responsible for any damage to hardware
// or software; spelling mistakes; tardiness; or waking your mother at
// 3:00 a.m. because the JavaScript said it was 3:00 p.m. in Denver.
//
//                                        Stuart Price
//                                        Forest Industries
//                                        stuart@4est.com
//                                        http://www.4est.com/

// get the date and change it to GMT string
var date = new Date();
var timegmt = date.toGMTString();

// split the GMT string at spaces
time_string = timegmt.split(' ');

// assign variables
week = time_string[0];
day = time_string[1];
mon = time_string[2];
year = time_string[3];
hms = time_string[4];

// split the time part on colon
hms_string = hms.split(':');

// assign variables
var hour = hms_string[0] - 0;
var min = hms_string[1];

// convert day-of-week variables to numbers
if (week == 'Sun,') {
   week = 1
   }
if (week == 'Mon,') {
   week = 2
   }
if (week == 'Tue,') {
   week = 3
   }
if (week == 'Wed,') {
   week = 4
   }
if (week == 'Thu,') {
   week = 5
   }
if (week == 'Fri,') {
   week = 6
   }
if (week == 'Sat,') {
   week = 7
   }

// make array for days of week
weekly = new Array("Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday");


   
// assign +- hour for San Francisco
var sf_hour = hour - 7;
var sf_week = week;
var sf_ampm = " a.m.";
if (sf_hour < 0) {
   sf_hour += 24
   sf_week -= 1
   }
if (sf_hour > 11) {
    sf_ampm = " p.m."
    }
if (sf_hour > 12) {
   sf_hour -= 12
   }
if (sf_hour == 0) {
   sf_hour = 12
   }

// assign +- hour for Denver
var den_hour = hour - 6;
var den_week = week;
var den_ampm = " a.m.";
if (den_hour < 0) {
   den_hour += 24
   den_week -= 1
   }
if (den_hour > 11) {
    den_ampm = " p.m."
    }
if (den_hour > 12) {
   den_hour -= 12
   }
if (den_hour == 0) {
   den_hour = 12
   }
     
// assign +- hour for Memphis
var mem_hour = hour - 5;
var mem_week = week;
var mem_ampm = " a.m.";
if (mem_hour < 0) {
   mem_hour += 24
   mem_week -= 1
   }
if (mem_hour > 11) {
    mem_ampm = " p.m."
    }
if (mem_hour > 12) {
   mem_hour -= 12
   }
if (mem_hour == 0) {
   mem_hour = 12
   }

// assign +- hour for New York
var ny_hour = hour - 4;
var ny_week = week;
var ny_ampm = " a.m.";
if (ny_hour < 0) {
   ny_hour += 24
   ny_week -= 1
   }
if (ny_hour > 11) {
    ny_ampm = " p.m."
    }
if (ny_hour > 12) {
   ny_hour -= 12
   }
if (ny_hour == 0) {
   ny_hour = 12
   }
   
// assign +- hours for London
var lon_hour = hour + 1;
var lon_week = week;
var lon_ampm = " a.m.";
if (lon_hour > 24) {
   lon_hour -= 24
   lon_week += 1
   }
if (lon_hour > 11) {
    lon_ampm = " p.m."
    }
if (lon_hour > 12) {
   lon_hour -= 12
   }
if (lon_hour == 0) {
   lon_hour = 12
   }
   
// assign +- hours for Paris
var par_hour = hour + 2;
var par_week = week;
var par_ampm = " a.m.";
if (par_hour > 24) {
   par_hour -= 24
   par_week += 1
   }
if (par_hour > 11) {
    par_ampm = " p.m."
    }
if (par_hour > 12) {
   par_hour -= 12
   }
if (par_hour == 0) {
   par_hour = 12
   }
   
// assign +- hours for Moscow
var mos_hour = hour + 3;
var mos_week = week;
var mos_ampm = " a.m.";
if (mos_hour > 24) {
   mos_hour -= 24
   mos_week += 1
   }
if (mos_hour > 11) {
    mos_ampm = " p.m."
    }
if (mos_hour > 12) {
   mos_hour -= 12
   }
if (mos_hour == 0) {
   mos_hour = 12
   }
   
// assign +- hours for Moscow
var ban_hour = hour + 7;
var ban_week = week;
var ban_ampm = " a.m.";
if (ban_hour > 24) {
   ban_hour -= 24
   ban_week += 1
   }
if (ban_hour > 11) {
    ban_ampm = " p.m."
    }
if (ban_hour > 12) {
   ban_hour -= 12
   }
if (ban_hour == 0) {
   ban_hour = 12
   }
     
// assign +- hours for Tokyo
var tok_hour = hour + 9;
var tok_week = week;
var tok_ampm = " a.m.";
if (tok_hour > 24) {
   tok_hour -= 24
   tok_week += 1
   }
if (tok_hour > 11) {
    tok_ampm = " p.m."
    }
if (tok_hour > 12) {
   tok_hour -= 12
   }
if (tok_hour == 0) {
   tok_hour = 12
   }
   
//-->
     
</script>

</HEAD>

<BODY BGCOLOR="#FFFFFF">


<script language="javascript1.2">
<!-- hideme
var loc_hour = date.getHours();
var loc_min = date.getMinutes();
var loc_ampm = " a.m.";
if (loc_hour > 11) {
    loc_ampm = " p.m."
    }
if (loc_hour > 12) {
    loc_hour -= 12
    }
document.write('<font size=2>Note: Your local time is </font>');
document.write(loc_hour + ':' + loc_min + loc_ampm);
document.write('<font size=2>  Times listed in the following table are based on your computer's time.  If your computer's clock is wrong, so is this table.</font>');
//-->
</script>

<table cellspacing=10>
<tr><td align=center valign=top>

<script language="javascript1.2">
<!-- hide it
document.write('<b>San Francisco</b><br>');
document.write(weekly[sf_week] + '<br>');
document.write(sf_hour + ':' + min + sf_ampm + '<br>');
//-->
</script>

</td><td align=center valign=top>

<script language="javascript1.2">
<!-- hide it
document.write('<b>Denver</b><br>');
document.write(weekly[den_week] + '<br>');
document.write(den_hour + ':' + min + den_ampm + '<br>');
//-->
</script>

</td><td align=center valign=top>

<script language="javascript1.2">
<!-- hide it
document.write('<b>Memphis</b><br>');
document.write(weekly[mem_week] + '<br>');
document.write(mem_hour + ':' + min + mem_ampm + '<br>');
//-->
</script>

</td><td align=center valign=top>

<script language="javascript1.2">
<!-- hide it
document.write('<b>New York</b><br>');
document.write(weekly[ny_week] + '<br>');
document.write(ny_hour + ':' + min + ny_ampm + '<br>');
//-->
</script>

</td><td align=center valign=top>

<script language="javascript1.2">
<!-- hide it
document.write('<b>London</b><br>');
document.write(weekly[lon_week] + '<br>');
document.write(lon_hour + ':' + min + lon_ampm + '<br>');
//-->
</script>

</td></TR><TR><td align=center valign=top>

<script language="javascript1.2">
<!-- hide it
document.write('<b>Paris</b><br>');
document.write(weekly[par_week] + '<br>');
document.write(par_hour + ':' + min + par_ampm + '<br>');
//-->
</script>

</td><td align=center valign=top>

<script language="javascript1.2">
<!-- hide it
document.write('<b>Moscow</b><br>');
document.write(weekly[mos_week] + '<br>');
document.write(mos_hour + ':' + min + mos_ampm + '<br>');
//-->
</script>

</td><td align=center valign=top>

<script language="javascript1.2">
<!-- hide it
document.write('<b>Bangkok</b><br>');
document.write(weekly[ban_week] + '<br>');
document.write(ban_hour + ':' + min + ban_ampm + '<br>');
//-->
</script>

</td><td align=center valign=top>

<script language="javascript1.2">
<!-- hide it
document.write('<b>Tokyo</b><br>');
document.write(weekly[tok_week] + '<br>');
document.write(tok_hour + ':' + min + tok_ampm + '<br>');
//-->
</script>

</td></tr>
</table>



</body>
</html>

Fechas y horarios