Joomla.it Forum
Joomla! 2.5 (versione con supporto terminato) => Joomla! 1.6/1.7/2.5 => : pot79 18 Dec 2012, 12:44:40
-
Salve a tutti!
Premetto che ho già cercato nel forum se qualche altro utente avesse avuto il mio stesso problema, ma non ho trovato nulla di esaudiente.
Vi spiego brevemente: sto creando un sito per un'azienda che organizza viaggi, e nelle pagine dedicate alle singole nazioni, vorrei inserire l'orario corrente della capitale, come fanno su questo sito (http://www.tailor-made.co.uk/holidays/new-zealand.aspx): è vero, è stato creato in ASP, ma l'orario corrente viene ottenuto tramite questo codice JS
function showTime()
{
var offset=10;
var offsetminute=0;
if(offset<0)
{
offsetminute = (-1)*offsetminute;
}
if (!document.all&&!document.getElementById)
return;
thelement=document.getElementById?document.getElementById("tick2"):document.all.tick2;
var now = new Date();
Date.prototype.addHours = function (n){this.setHours (this.getHours () + n)}
Date.prototype.toDateString = function () {return [this.getDate(), this.getMonth() + 1, this.getFullYear()].join ('-')}
Date.prototype.toString = function () {return [this.toDateString(), this.toTimeString()].join (' ')}
now.addHours(offset);
now.setMinutes(now.getMinutes() +offsetminute);
var hours=now.getHours();
var minutes=now.getMinutes();
var seconds=now.getSeconds();
var dn='PM';
if (hours<12)
dn='AM';
if(hours>12)
hours=hours-12;
if (hours==0)
hours=12;
if (minutes<=9)
minutes='0'+minutes;
if (seconds<=9)
seconds='0'+seconds;
var ctime=' '+hours+':'+minutes+':'+seconds+' '+dn;
thelement.innerHTML=ctime;
setTimeout('showTime()',1000);
}
window.onload=showTime;
Ho provato a cercare nello JED ma non ho veramente trovato nessun plugin che simuli una cosa simile; quindi avevo pensato di sfruttare qualche plugin che ti permette di inserire manualmente il proprio codice.
Sourcerer (http://extensions.joomla.org/extensions/core-enhancements/coding-a-scripts-integration/custom-code-in-content/5051) non posso usarlo perchè la versione PHP non è la 5.3 (maledettissimo provider)...mi sono diretto quindi su Embed Script (http://extensions.joomla.org/extensions/core-enhancements/coding-a-scripts-integration/custom-code-in-content/16063).
Installato plugin, abilitato e inserito codice: funziona alla grande e cliccando qui (http://demo3.andreabellidesign.it/index.php/destinazioni/africa/botswana) potete vederlo tranquillamente in opera.
Unica cosa che ancora stona è il fatto che, almeno per quanto riguarda la versione del sito in Italiano, quel AM-PM non si può proprio vedere: non sono un mago del JS, ma se leggo del codice più o meno sò comprendere qualcosa...ho provato a fare così
function showTime()
{
var offset=10;
var offsetminute=0;
if(offset<0)
{
offsetminute = (-1)*offsetminute;
}
if (!document.all&&!document.getElementById)
return;
thelement=document.getElementById?document.getElementById("tick2"):document.all.tick2;
var now = new Date();
Date.prototype.addHours = function (n){this.setHours (this.getHours () + n)}
Date.prototype.toDateString = function () {return [this.getDate(), this.getMonth() + 1, this.getFullYear()].join ('-')}
Date.prototype.toString = function () {return [this.toDateString(), this.toTimeString()].join (' ')}
now.addHours(offset);
now.setMinutes(now.getMinutes() +offsetminute);
var hours=now.getHours();
var minutes=now.getMinutes();
var seconds=now.getSeconds();
if (minutes<=9)
minutes='0'+minutes;
if (seconds<=9)
seconds='0'+seconds;
var ctime=' '+hours+':'+minutes+':'+seconds+';
thelement.innerHTML=ctime;
setTimeout('showTime()',1000);
}
window.onload=showTime;
ma non mi fa vedere un bel niente.
Qualche idea per bypassare questo intoppo?
-
Un idea potrebbe essere di utilizzare un modulo che ti mostra l'ora e poi crei tanti duplicati del modulo quante sono le nazioni e ne pubblichi uno per nazione (ovviamente cambiando l'ora)..
prova a vedere nel jed http://extensions.joomla.org/extensions/calendars-a-events/time/clocks
-
Grazie fasenderos, ma ho risolto ;D
non funzionava per colpa di un apice e un + di troppo... :o
Ricapitolando, per chi dovesse averne bisogno:
1- installate un plugin che vi permetta di inserire codice JS all'interno di un contenuto (io ho usato Embed Script)
2- ricordatevi di abilitarlo
3- disabilitate l'editor di testo
4- andate all'interno del contenuto dove volete far comparire l'orario e scrivete questo codice
FORMATO 24h SENZA AM/PM
Orario a NomeCapitale:
{js}
function showTime()
{
var offset=10;
var offsetminute=0;
if(offset<0)
{
offsetminute = (-1)*offsetminute;
}
if (!document.all&&!document.getElementById)
return;
thelement=document.getElementById?document.getElementById("tick2"):document.all.tick2;
var now = new Date();
Date.prototype.addHours = function (n){this.setHours (this.getHours () + n)}
Date.prototype.toDateString = function () {return [this.getDate(), this.getMonth() + 1, this.getFullYear()].join ('-')}
Date.prototype.toString = function () {return [this.toDateString(), this.toTimeString()].join (' ')}
now.addHours(offset);
now.setMinutes(now.getMinutes() +offsetminute);
var hours=now.getHours();
var minutes=now.getMinutes();
var seconds=now.getSeconds();
if (minutes<=9)
minutes='0'+minutes;
if (seconds<=9)
seconds='0'+seconds;
var ctime=' '+hours+':'+minutes+':'+seconds;
thelement.innerHTML=ctime;
setTimeout('showTime()',1000);
}
window.onload=showTime; {/js}<span id="tick2"></span>
FORMATO 12h CON AM/PM
Current Time in NomeCapitale is:
{js}
function showTime()
{
var offset=10;
var offsetminute=0;
if(offset<0)
{
offsetminute = (-1)*offsetminute;
}
if (!document.all&&!document.getElementById)
return;
thelement=document.getElementById?document.getElementById("tick2"):document.all.tick2;
var now = new Date();
Date.prototype.addHours = function (n){this.setHours (this.getHours () + n)}
Date.prototype.toDateString = function () {return [this.getDate(), this.getMonth() + 1, this.getFullYear()].join ('-')}
Date.prototype.toString = function () {return [this.toDateString(), this.toTimeString()].join (' ')}
now.addHours(offset);
now.setMinutes(now.getMinutes() +offsetminute);
var hours=now.getHours();
var minutes=now.getMinutes();
var seconds=now.getSeconds();
var dn='PM';
if (hours<12)
dn='AM';
if(hours>12)
hours=hours-12;
if (hours==0)
hours=12;
if (minutes<=9)
minutes='0'+minutes;
if (seconds<=9)
seconds='0'+seconds;
var ctime=' '+hours+':'+minutes+':'+seconds+' '+dn;
thelement.innerHTML=ctime;
setTimeout('showTime()',1000);
}
window.onload=showTime; {/js}<span id="tick2"></span>
NOTA BENE
la terza riga di questo codice (var offset=10;) è quella che imposta il fuso orario della nazione che state prendendo in considerazione...nel codice che vi ho scritto si riferisce all'Australia; quindi non dimenticate di impostare il giusto valore.
Ciao a tutti!!! ;)
-
Ottimo lavoro pot79.
-
Grazie maicolstaip, è un piacere ogni tanto poter dare una mano...di solito qui dentro trovo soluzioni ai miei di problemi ;)