[Javascript] Calendario

« Older   Newer »
  Share  
CAT_IMG Posted on 17/12/2008, 06:42     +1   -1

Targhette Utente

Group:
Member
Posts:
20,636
Reputation:
0

Status:


CODICE
<!-- Prelevato nel Forum di Supporto di ForumFree.net e ForumCommunity.net -->
<script type="text/javascript">setCal();
function getTime(){var now=new Date(); var hour=now.getHours(); var minute=now.getMinutes(); now=null; var ampm=""; if(hour>=12){hour-=12; ampm="PM"} else ampm="AM"; hour=hour==0 ? 12 : hour; if(minute<10) minute="0"+minute; return hour+":"+minute+" "+ampm}
function leapYear(year){return year % 4==0 ? true : false}
function getDays(month,year){var x=new Array(31,(leapYear(year) ? 29 : 28),31,30,31,30,31,31,30,31,30,31); return x[month]}
function getMonthName(month){var y=new Array("Gennaio", "Febbraio", "Marzo", "Aprile", "Maggio", "Giugno", "Luglio", "Agosto", "Settembre", "Ottobre", "Novembre", "Dicembre"); return y[month]}
function setCal(){var now=new Date(); var year=now.getFullYear(); var month=now.getMonth(); var monthName=getMonthName(month); var date=now.getDate(); now=null; var firstdayInstance=new Date(year,month,1); var firstday=firstdayInstance.getDay(); firstdayInstance=null; var days=getDays(month,year); drawCal(firstday+1, days, date, monthName, year)}

function drawCal(firstday, lastDate, date, monthName, year) {
var topHeight=20 // height of the table's top cell
var border=4 // 3D height of table's border
var cellspacing=3 // width of table's border
var topColor="midnightblue" // color of table's top
var topSize="+1" // size of tables top font
var colWidth=30 // width of columns in table
var dayCellHeight=15 // height of cells containing days of the week
var dayColor="darkblue" // color of font representing week days
var cellHeight=20 // height of cells representing dates in the calendar
var todayColor="red" // color specifying today's date in the calendar
var timeColor="purple" // color of font representing current time
var text=""
text+='<table border='+border+' cellspacing='+cellspacing+'>' // table settings
text+='<th colspan=7 height='+topHeight+'>' // create table top cell
text+='<font face="verdana" color="'+topColor+'" size='+topSize+'>' // set font for table top
text+=monthName+' '+year
text+='</font>' // close table top's font settings
text+='</th>' // close top cell

var openCol='<td width='+colWidth+' height='+dayCellHeight+'>'; openCol+='<font face="verdana" color="'+dayColor+'">'; var closeCol='</font>'; var weekDay=new Array("Dom","Lun","Mar","Mer","Gio","Ven","Sab"); text+='<tr align="center" valign="center">'; for(var dayNum=0; dayNum<7; ++dayNum){text+=openCol+weekDay[dayNum]+closeCol} var digit=1; var curCell=1; for(var row=1; row<=Math.ceil((lastDate+firstday-1)/7); ++row){text+='<tr align="right" valign="top">'; for(var col=1; col<=7; ++col){if(digit>lastDate) break; if(curCell<firstday){text+='<td>'; curCell++} else{if(digit==date){text+='<td height='+cellHeight+'>'; text+='<b><font face="verdana" color="'+todayColor+'"></b>'; text+=digit; text+='</font><br>'; text+='<font face="verdana" color="'+timeColor+'" size="2">'; text+='</font>'} else text+='<td HEIGHT='+cellHeight+'><font face="verdana">'+digit+'</font>'; digit++}}} text+='</table>'; document.write(text)}</script>
 
Top
0 replies since 17/12/2008, 06:42   36 views
  Share