Orario am – pm

Postato il: 5 aprile 2009 | Nella categoria: JavaScript » Script

Se preferisci avere, sul sito web, un orologio che “all’americana” che ti segni am e pm, devi inserire il seguente script all’interno dei tag head:

<script language="JavaScript" type="text/javascript">
<!-- Copyright 2003, Sandeep Gangadharan -->
<!-- For more free scripts go to http://www.sivamdesign.com/scripts/ -->
<!-- 
 
function sivamtime() {
  now=new Date();
  hour=now.getHours();
  min=now.getMinutes();
  sec=now.getSeconds();
 
if (min<=9) { min="0"+min; }
if (sec<=9) { sec="0"+sec; }
if (hour>12) { hour=hour-12; add="pm"; }
else { hour=hour; add="am"; }
if (hour==12) { add="pm"; }
 
time = ((hour<=9) ? "0"+hour : hour) + ":" + min + ":" + sec + " " + add;
 
if (document.getElementById) { document.getElementById('theTime').innerHTML = time; }
else if (document.layers) {
 document.layers.theTime.document.write(time);
 document.layers.theTime.document.close(); }
 
setTimeout("sivamtime()", 1000);
}
window.onload = sivamtime;
 
// -->
 
</script>

Mentre il seguento codice va posizionato all’interno dei tag body:

<span id="theTime" style="font-weight: bold; font-family: arial; font-size: 10pt"></span>

Articoli simili:

Sono stati inviati 0 commenti - Invia un commento

Lascia un commento