Grazie Andrea.
Questo codice fa parte di un codice più complesso che calcola il fuso orario tra due città, nell'esempio è tra Roma e Los Angeles.
Però ho due problemi che non riesco a risolvere:
1) Le date sono incongruenti nel senso che quando a Roma è 01 ottobre ed a L.A. è ancora il 30 settembre (-5 ore), per L.A. viene indicata erroneamente la data del 01 ottobre;
2) Come è possibile rendere gli orari dinamici, cioè con i secondi che si vedono scorrere sul browser?
Codice:
codice:
<script language="javascript1.2">
<!--
// get the date and change it to GMT string
var date = new Date();
var timegmt = date.toGMTString();
var Anno = date.getYear();
var Mese = date.getMonth()+1;
var Giorno = date.getDate();
Giorno = (Giorno/10 < 1 ? '0'+Giorno: Giorno);
DatadiOggi = Giorno + "/" + Mese + "/" + Anno
// 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("Sab", "Dom", "Lun", "Mar", "Mer", "Gio", "Ver", "Sab", "Dom");
//Orario Los Angeles
var den_hour = hour - 5;
var den_week = week;
var den_ampm = " ";
if (den_hour < 0) {
den_hour += 24
den_week -= 1
}
// Orario Roma
var lon_hour = hour + 2;
var lon_week = week;
var lon_ampm = " ";
if (lon_hour > 24) {
lon_hour -= 24
lon_week += 1
}
//-->
</script>
<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
}
//-->
</script>
<script language="javascript1.2">
<!-- hide it
document.write('Orario Los Angeles
');
document.write(weekly[den_week] + ' - ');
document.write(DatadiOggi + "
")
document.write(den_hour + ':' + min + den_ampm + '
');
//-->
</script>
<script language="javascript1.2">
<!-- hide it
document.write('Orario Roma (Italia)
');
document.write(weekly[lon_week] + ' - ');
document.write(DatadiOggi + "
")
document.write(lon_hour + ':' + min + lon_ampm + '
');
//-->
</script>