1 <%@ page language="java" contentType="text/html; charset=gb2312" %> 2 <%@ page language="java" import="java.util.*" %> 3 <% 4 String[] weekdays={"","日","一","二","三","四","五","六"}; 5 String[] days=new String[42]; 6 for(int i=0;i<42;i++) 7 days[i]=""; 8 9 GregorianCalendar currentDay = new GregorianCalendar(); 10 int year= currentDay.get(Calendar.YEAR); 11 int month=currentDay.get(Calendar.MONTH); 12 int today=currentDay.get(Calendar.DAY_OF_MONTH); 13 int weekday=currentDay.get(Calendar.DAY_OF_WEEK); 14 15 String now=year+"年"+(month+1)+"月"+today+"日"+" 星期"+weekdays[weekday]; 16 17 Calendar thisMonth=Calendar.getInstance(); 18 thisMonth.set(Calendar.MONTH, month ); 19 thisMonth.set(Calendar.YEAR, year ); 20 thisMonth.setFirstDayOfWeek(Calendar.SUNDAY); 21 thisMonth.set(Calendar.DAY_OF_MONTH,1); 22 23 int firstIndex=thisMonth.get(Calendar.DAY_OF_WEEK)-1; 24 int maxIndex=thisMonth.getActualMaximum(Calendar.DAY_OF_MONTH); 25 for(int i=0;i<maxIndex;i++){ 26 days[firstIndex+i]=String.valueOf(i+1); 27 } 28 %> 29 30 <html> 31 <head> 32 <title>简易万年历</title> 33 <link type="text/css" rel="stylesheet" href="<s2:url value='css/style.css'/>"> 34 <script type="text/javascript"> 35 function showTime(showWhere){ 36 var now=new Date(); 37 var hour=now.getHours(); 38 var minu=now.getMinutes(); 39 var sec=now.getSeconds(); 40 41 if(hour<10) hour="0"+hour; 42 if(minu<10) minu="0"+minu; 43 if(sec<10) sec="0"+sec; 44 45 showWhere.value=hour+":"+minu+":"+sec; 46 setTimeout("showTime(time)",1000) 47 } 48 </script> 49 </head> 50 <body onload="showTime(time)"> 51 <table width="210" border="0" align="center" cellspacing="1" > 52 <tr height="25"><td colspan="7" align="center" style="border:0 solid"><%=now%> <input type="text" style="border:0;background-color:#F9F9F9" disable="true" id="time" size="9"></td></tr> 53 <tr height="25" bgcolor="#F0F0F0" align="center"> 54 <td style="border:1 solid">日</td> 55 <td style="border:1 solid">一</td> 56 <td style="border:1 solid">二</td> 57 <td style="border:1 solid">三</td> 58 <td style="border:1 solid">四</td> 59 <td style="border:1 solid">五</td> 60 <td style="border:1 solid">六</td> 61 </tr> 62 <tr height="4"><td colspan="7"></td></tr> 63 <% for(int j=0;j<6;j++) { %> 64 <tr> 65 <% 66 for(int i=j*7;i<(j+1)*7;i++) { 67 if((i-firstIndex+1)==today){%> 68 <td width="30" height="23" align="center" bgcolor="gray" style="border:1 solid"><font color="#FFFFFF"><b><%=days[i]%></b></font></td> 69 <% }else{ %> 70 <td width="30" height="23" align="center" style="border:1 solid"><%=days[i]%></td> 71 <% } 72 }%> 73 </tr> 74 <% } %> 75 <tr height="10"><td colspan="7"></td></tr> 76 </table> 77 </body> 78 </html>