Newsgroup: it.comp.lang.javascript
Titolo: JS che calcoli quanto manca al 2000

Ciao a tutti,
io sto cercando uno JS che mi calcoli quanto sopra, in italiano,
perchè ne ho uno, ma è in inglese.
Grazie a tutti quelli che mi aiuteranno (è possibile modificare quello
in mio possesso affinchè dia p.e. anno e non year ecc???).

...
Ciao a tutti,


----------
Sicuramente puoi modificare il codice in tuo possesso per viasualizzare anno
al posto di year, ma se vuoi un codice completo,
prova questo trovato su 
http://www.html.it
:
<HEAD>
<SCRIPT Language="JavaScript">
<!-- Hiding script from old browsers
/************************************************************************/
/*                                                                      */
/*      Copyright (C) 1996  Glub, Un-Inc.  All Rights Reserved.         */
/*      Feel free to reuse or modify this code,                         */
/*      provided this header remains in tact.                           */
/*      [
http://www.dotdotcom.com/
] [
http://sdcc8.ucsd.edu/~gcohen/
]    */
/*                                                                      */
/************************************************************************/
/* Initializations */
var timerID;
var timerRunning = false;
var today = new Date();
var enday = new Date();
var secPerDay = 0;
var minPerDay = 0;
var hourPerDay = 0;
var secsLeft = 0;
var secsRound = 0;
var secsRemain = 0;
var minLeft = 0;
var minRound = 0;
var minRemain = 0;
var timeRemain = 0;
/* This function will stop the clock */
function stopclock (){
if(timerRunning)
clearTimeout(timerID);
timerRunning = false;
}
/* This function will start the clock */
function startclock () {
stopclock();
showtime();
}
/*
This is the heart of the script
today is the date today, wow.
enday is the date you want to count til. For this example enday is the year
2000.
secsPerDay will be used to get the seconds per day, double wow.
you should be able to figure out minPerDay, hoursPerDay, and PerDay.
*/
function showtime () {
today = new Date();
enday = new Date("December, 31 1999 23:59");
enday.setYear("1999");
secsPerDay = 1000 ;
minPerDay = 60 * 1000 ;
hoursPerDay = 60 * 60 * 1000;
PerDay = 24 * 60 * 60 * 1000;
/*Seconds*/
/*
secsLeft is the raw seconds remaining until the date.
secsRound is the rounded seconds remaining until the date.
secsRemain is the re-configured seconds. The seconds need to be
limited from 59 to 0 much like a real clock counts. This will do it.
*/
secsLeft = (enday.getTime() - today.getTime()) / minPerDay;
secsRound = Math.round(secsLeft);
secsRemain = secsLeft - secsRound;
secsRemain = (secsRemain < 0) ? secsRemain = 60 - ((secsRound - secsLeft) *
60) : secsRemain = (secsLeft - secsRound) * 60;
secsRemain = Math.round(secsRemain);
/*Minutes*/
/*
minLeft is the raw minutes remaining until the date.
minRound is the rounded seconds remaining until the date.
minRemain is the re-configured minutes. The minutes need to be
limited from 59 to 0 much like a real clock. Gosh I feel like a
skipping record. Oh well.
*/
minLeft = ((enday.getTime() - today.getTime()) / hoursPerDay);
minRound = Math.round(minLeft);
minRemain = minLeft - minRound;
minRemain = (minRemain < 0) ? minRemain = 60 - ((minRound - minLeft)  * 60)
: minRemain = ((minLeft - minRound) * 60);
minRemain = Math.round(minRemain - 0.495);
/*Hours*/
/*
hoursLeft is the raw hours remaining until the date.
hoursRound is the rounded hours remaining until the date.
hoursRemain is the re-configured hours. The hours need to be
limited from 23 to 0 much like a real clock. I think you're starting
to get the picture, no?
*/
hoursLeft = ((enday.getTime() - today.getTime()) / PerDay);
hoursRound = Math.round(hoursLeft);
hoursRemain = hoursLeft - hoursRound;
hoursRemain = (hoursRemain < 0) ? hoursRemain = 24 - ((hoursRound -
hoursLeft)  * 24) : hoursRemain = ((hoursLeft - hoursRound) * 24);
hoursRemain = Math.round(hoursRemain - 0.5);
/*Days*/
/*
daysLeft is the raw days remaining until the date.
daysRound is the rounded days remaining until the date.
daysRemain is the re-configured days. The days need to be
rounded, guess daysRound is not needed, but it sure looks
good don't it?
*/
daysLeft = ((enday.getTime() - today.getTime()) / PerDay);
daysLeft = (daysLeft - 0.5);
daysRound = Math.round(daysLeft);
daysRemain = daysRound;
/*Time*/
/*
timeRemain makes the clock more elegant.
document.clock.face.value is used to show the time remaining.
timeID controls the refresh rate of the clock. The number is the rate in
milliseconds.
The if statement will stop the clock when the time has expired.
*/
timeRemain = daysRemain + " giorni, " + hoursRemain + " ore, " + minRemain +
" minuti, " + secsRemain + " secondi";
document.clock.face.value = timeRemain;
timerID = setTimeout("showtime()",1000);
timerRunning = true;
if (daysRemain < 0) {
clearTimeout(timerID);
timerRunning = false;
document.clock.face.value = "Time Has Expired";
}
}
// end hiding contents from old browsers  -->
</SCRIPT>
</HEAD>
<BODY onLoad="startclock()">
<CENTER> <FORM name="clock" onSubmit="0"><INPUT type="text" name="face"
size=50 value=""></FORM></CENTER>
</BODY>
Ciao!
Stefano on Line
http://members.xoom.com/StefanOnLine

perchè ne ho uno, ma è in inglese.
~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~
Gabriele Bertolucci - NT4WKSITA+SP3 - VB5PROITA+SP3
pbe...@vi.ats.it
pbe...@freemail.it
 (alias)
pbe...@bigfoot.com
 (alias)
http://members.spree.com/sip/pberto/
http://userspace.ats.it/free/pberto/
 (alias)
http://www.fortunecity.com/skyscraper/spiff/523/
 (alias)
http://www.bigfoot.com/~pberto/
 (alias)
ICQ #: 9732192
~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~