Attenzione! Javascript è disabilitato
Listings created for the calculation of the Julian Day number (J.D), using JavaScript & AstroJS.
Before commencing, connect your Html page to the Astrojs library, pasting the following listing, under the tag <title>.
IMPORTANT! The functions in red, are not Javascript commands, but belong to the Astrojs library.
<script type="text/javascript" src="http://www.suchelu.it/astrojs/astrojs.js"></script>
<script language="JavaScript" type="text/javascript"> //<!-- var njd=calcola_jd(); // (1)Calculate J.D. reported at the time of Greenwich in this instant. document.write(njd); // writes the result. //--> </script>
//The line (1) can be replaced with one of the following functions ... var njd=calcola_jdUT0(); // calculates the J.D. for the time 0 (zero) in U.T. today var njd=calcola_jda(); // calculates the J.D. for the beginning of this year. var njd=calcola_jd_anno(yy); // J.D. for the beginning of the year specified in the parameter (yy). var njd=calcola_jddata(dd,mm,yy,hh,mi,se); // Calculate J.D. for any date.
<script language="JavaScript" type="text/javascript"> //<!-- //calculates the J.D. for the date specified in the variables. var dd=23; // day. var mm=6; // month. var yy=2011; // year. var hh=10; // hours. var mi=20; // minutes. var se=30.256; // seconds (may have decimals). var njd=calcola_jddata(dd,mm,yy,hh,mi,se); document.write(njd); // writes the results. //--> </script>
The first seven lines of the listing, can be reduced to a minimum, with the inclusion of the numerical values of the date, directly in the function:
var njd=calcola_jddata(23,6,2011,10,20,30.256); // Date.
Attention to the comma ( , ) used for the separation of the parameters from the one for decimal numbers ( . ).
<script language="JavaScript" type="text/javascript"> //<!-- //Gets the date (dd,mm,yy) known number of Julian Day. var njd=2455735.93; // Enter the number of J.D. date. var data=jd_data(njd); // array dates calendar. // writes results. document.write(data[0]+" | "); // day on decimals hours. document.write(data[1]+" | "); // month. document.write(data[2]+" | "); // year. document.write(data[3]+" | "); // day of the week in Italian document.write(data[4]+" || "); // day of the week in English document.write(data[5]+" || "); // numerical value on day of the week (0,1,2, ..6). var day=sc_day(data[0]); // sc_day divide the day in dd,hh,mm,ss. document.write(day); // day,hours,minutes,seconds //--> </script>
In order to calculate in what day of the week a certain date falls on, use this listing…
<script language="JavaScript" type="text/javascript"> //<!-- //recovers the day of the week. var dd=12; // day. var mm=10; // month. var yy=1492; // year. var hh=2; // hours var mi=0; // minutes var se=0; // seconds var njd=calcola_jddata(dd,mm,yy,hh,mi,se); // J.D. Date var data=jd_data(njd); // day of the week document.write(data[4]); // day of the week in english (abbreviated). // For the 12 October 1492 the result is: "Fr" - which corresponds to Friday. //--> </script>
<script language="JavaScript" type="text/javascript"> //<!-- //number of days elapsed since the beginning of the year. var njd=calcola_jd();; // J.D. today. var njd_ia=calcola_jda(); ; // J.D. for beginning of the year. var num_day=njd-njd_ia; // elapsed days. num_day=parseInt(num_day); // remove decimals. document.write("Elapsed Days : "+num_day); // writes the results. //--> </script>
With a listing similar to the previous one it is possible to obtain the days that passed between any two events; all you have to do is use the function calculate_jddate(dd,mm,yy,hh,mi,se). replacing the two previous ones and inserting the two dates in the parameters…
<script language="JavaScript" type="text/javascript"> //<!-- //Obtain the days that passed between two events. var njd=calcola_jddata(23,6,1986,0,0,0); // Date1: 23-06-1986. var njd_ia=calcola_jddata(23,1,2011,0,0,0); // Date2: 23-01-2011. var num_giorno=njd-njd_ia; // the number of elapsed days. num_giorno=parseInt(num_giorno); // delete the decimals. document.write("the number of days elapsed: "+num_giorno+"!"); // writes the results. //--> </script>
To estimate the number of days elapsed since the beginning of the year, using the last listing; you must enter 0 in January, instead of January 1: calculate_jddate(0,1,2011,0,0,0), which corresponds to January 0, 2011.
Using the julian numbering system, it is easy to create a simple Countdown…
<p id="posdata">posizione del countdown</p> <!-- Position of the date in HTML document --> <script language="JavaScript" type="text/javascript"> //<!-- //Countdown (listing 1) var njd_cd=calcola_jddata(23,12,2012,0,0,0); // Countdown date. countdown(njd_cd); function countdown(njd_cd) { var njd=calcola_jd();; // the J.D. today. var num_giorno=njd_cd-njd; // number elapsed days. num_giorno=sc_day(num_giorno); // Date formatting. document.getElementById("posdata").innerHTML=(""+num_giorno); } z=setInterval("countdown(njd_cd)",1000); //--> </script>
If you are not satisfied with the type of date format, you can eliminate the function sc_day(...) and “manually” calculate the times.
var dd_dec=Math.abs(num_giorno); // absolute value. var dd=parseInt(dd_dec); // days. var hh=parseInt((dd_dec-dd)*24); // hours. var mm=parseInt(((dd_dec-dd)*24-hh)*60); // minutes. var ss=parseInt(((((dd_dec-dd)*24-hh)*60)-mm)*60); // seconds.
<h2 id="posdata">posizione del countdown</h2> <!-- Position of the date in HTML document --> <script language="JavaScript" type="text/javascript"> //<!-- //Countdown (listing 2). var njd_cd=calcola_jddata(23,12,2012,0,0,0); // Countdown date. countdown(njd_cd); function countdown(njd_cd) { var njd=calcola_jd();; // J.D. today. var num_giorno=njd_cd-njd; // elapsed days. var dd_dec=Math.abs(num_giorno); // absolute value. var dd=parseInt(dd_dec); // days. var hh=parseInt((dd_dec-dd)*24); // hours. var mm=parseInt(((dd_dec-dd)*24-hh)*60); // minutes. var ss=parseInt(((((dd_dec-dd)*24-hh)*60)-mm)*60); // seconds. var date=dd+":"+hh+":"+mm+":"+ss; //days+hours+minutes+seconds. document.getElementById("posdata").innerHTML=(""+date); } z=setInterval("countdown(njd_cd)",1000); //--> </script>
//To get the seconds with (2) decimal places, replace the seconds line of (ss), with this:: var ss=(((((dd_dec-dd)*24-hh)*60)-mm)*60).toFixed(2); // the seconds with 2 decimals.
Using the J.D. it is possible to realize a calendar as this.
<script language="JavaScript" type="text/javascript"> var dd=new Array(""); var classed=new Array(""); // CSS Class var data=new Date(); // Date: var yy=data.getYear(); // recovers the current year var mm=data.getMonth(); // recovers the current month : 0 a 11 var dd0=data.getDate(); // recovers the number of current day from 1 at 31. mm=mm+1; // value of month between 1-12. if (yy<1900) {yy=yy+1900;} // correction of the year for the browser. var numbers_days=calcola_dd_mese(mm,yy);// calculates the number of day of the month: 28-31 var njd=calcola_jddata(1,mm,yy,0,0,0); // julian day of the first day of the month. var data_cal=jd_data(njd); var aa=data_cal[5]; // check which day of the week falls on the 1st day of the month. // return a number between 0,....6 0=Sunday 6=Saturday var nn_days=40; var nrows=5; // number of rows // if the first day of the month falls the Friday or Saturday, // adds a one row to calendar: rows=6. // adds 5 days to nn_giorni=45. if (data_cal[5]==6 || data_cal[5]==5 ) {nrows=6; nn_days=45; } for (c=0; c<nn_days; c++){ dd[c]=""; classed[c]="colore_tabellavv"; } for(b=1 ; b<numbers_days+1; b++){ dd[aa+b-1]=b; classed[aa+b-1]="colore_tabella"; if(b==dd0){classed[aa+b-1]="colore_tabellagg";} } // Create the table for the calendar var name_month=rec_month(mm); // Recovery of the current month. document.write("<div id='calendario'>"); document.write("<h3>"+name_month+" "+yy+"<h3>"); document.write("<table width=70%>"); document.write(" <tr>"); document.write(" <td width=10% class='colore_tabellaef2'>Sun</td>"); document.write(" <td width=10% class='colore_tabellaef2'>Mon</td>"); document.write(" <td width=10% class='colore_tabellaef2'>Tue</td>"); document.write(" <td width=10% class='colore_tabellaef2'>Wed</td>"); document.write(" <td width=10% class='colore_tabellaef2'>Thu</td>"); document.write(" <td width=10% class='colore_tabellaef2'>Fri</td>"); document.write(" <td width=10% class='colore_tabellaef2'>Sat</td>"); document.write(" </tr>"); z=0; for(a=0; a<nrows; a++) { document.write(" <tr>"); document.write(" <td class='"+classed[z]+ "'>"+dd[z]+"</td>"); document.write(" <td class='"+classed[z+1]+"'>"+dd[z+1]+"</td>"); document.write(" <td class='"+classed[z+2]+"'>"+dd[z+2]+"</td>"); document.write(" <td class='"+classed[z+3]+"'>"+dd[z+3]+"</td>"); document.write(" <td class='"+classed[z+4]+"'>"+dd[z+4]+"</td>"); document.write(" <td class='"+classed[z+5]+"'>"+dd[z+5]+"</td>"); document.write(" <td class='"+classed[z+6]+"'>"+dd[z+6]+"</td>"); document.write(" </tr>"); z=z+7; } document.write(" </table>"); document.write("</div>"); //Function for the Recovery of the current month. function rec_month(mm){ mm=mm-1; if(mm==0) {name_month="January"; } else if(mm==1) {name_month="February"; } else if(mm==2) {name_month="March"; } else if(mm==3) {name_month="April"; } else if(mm==4) {name_month="May"; } else if(mm==5) {name_month="June"; } else if(mm==6) {name_month="July"; } else if(mm==7) {name_month="August"; } else if(mm==8) {name_month="September"; } else if(mm==9) {name_month="October"; } else if(mm==10) {name_month="November"; } else if(mm==11) {name_month="December"; } return name_month; } </script>
#calendario{ background-color: #EEEEEE; width: 220px; border: 1px solid blue; margin: 0px; padding:0px;} table{ width: 100%; margin-bottom: 0px; padding-bottom: 0px;} h3{ text-align: center; padding: 0px; margin-top: 0px; border-bottom: 0px; font-family: Courier New; color: #990000;} #calendario td { color: black; font-family: Arial; font-size: 8pt; padding: 2px; margin: 2px; font-weight: normal; } .colore_tabellaef2{ background-color: gray; border: 1px solid gray; font-family: Arial, Helvetica, sans-serif; font-size: 10pt; } /* names of days */ .colore_tabella { background-color: #DDDDDD; } /* day of month */ .colore_tabellagg { background-color: #FF0033; font-weight: bold;} /* day of today */ .colore_tabellavv { background-color: #EEEEEE; } /* empty cells */
Riferimenti bibliografici:
JEAN MEEUS - Astronomia con il computer. ( Hoepli-1990 ) - PETER DUFFETT-SMITH -Astronomia pratica. ( Sansoni Studio 1981 )
FRANCESCO ZAGAR -Astronomia sferica e teorica ( Zanichelli 1988 )
Copyright ©2009 - Salvatore Ruiu
Tutti i contenuti del sito sono protetti dal diritto d'autore.
All Rights Reserved.
Questo sito è Online da dicembre 2009 || Ultima modifica: 10-Dicembre 2009 || Questa pagina web rispetta le direttive del W3C | CSS 2.1 | XHTML 1.0