效果图: %@ page language= "java" contentType= "text/html; charset=gb2312" % %@ page language= "java" import= "java.util.*" % % String [] weekdays={ "" , "日" , "一" , "二" , "三" , "四" , "五" , "六" }; String [] days= new String
效果图:
<%@ page language="java" contentType="text/html; charset=gb2312" %>
<%@ page language="java" import="java.util.*" %>
<% String[] weekdays={"","日","一","二","三","四","五","六"}; String[] days=new String[42]; for(int i=0;i<42;i++) days[i]=""; GregorianCalendar currentDay = new GregorianCalendar(); //获取年月日 int year= currentDay.get(Calendar.YEAR); int month=currentDay.get(Calendar.MONTH); int today=currentDay.get(Calendar.DAY_OF_MONTH); //这个月中的第几天 int weekday=currentDay.get(Calendar.DAY_OF_WEEK);//这个月的第几天 //修改日历字段值 Calendar thisMonth=Calendar.getInstance(); ///Calendar类的静态方法getInstance()可以初始化一个日历对象 thisMonth.set(Calendar.MONTH, month ); thisMonth.set(Calendar.YEAR, year); thisMonth.setFirstDayOfWeek(Calendar.SUNDAY); //设置一星期的第一天是星期几,这里设置成星期天 thisMonth.set(Calendar.DAY_OF_MONTH,1); //一个月中的某一天 int firstIndex=thisMonth.get(Calendar.DAY_OF_WEEK)-1; int maxIndex=thisMonth.getActualMaximum(Calendar.DAY_OF_MONTH); //maxIndex这个月的最大值, firstIndex星期几 for(int i=0;i<maxIndex;i++){ days[firstIndex+i]=String.valueOf(i+1); //得到当月的表格 } System.out.print(firstIndex+","+maxIndex); %>
<html>
<head>
<title>简易万年历</title>
<script type="text/javascript"> function showTime(showWhere){ var now=new Date(); var hour=now.getHours(); var minu=now.getMinutes(); var sec=now.getSeconds(); if(hour<10) hour="0"+hour; if(minu<10) minu="0"+minu; if(sec<10) sec="0"+sec; //给id赋值 showWhere.value=hour+":"+minu+":"+sec; setTimeout("showTime(time)",1000) //在1000ms后执行showTime函数 } </script>
</head>
<body onload="showTime(time)">
<table width="210" border="0" align="center" cellspacing="1" >
<tr height="25">
<td colspan="7" align="center" style="border:0 solid">
<input type="text" style="border:0;background-color:#F9F9F9" disable="true" id="time" size="9">
</td>
</tr>
<tr height="25" bgcolor="#F0F0F0" align="center">
<td style="border:1 solid">日</td>
<td style="border:1 solid">一</td>
<td style="border:1 solid">二</td>
<td style="border:1 solid">三</td>
<td style="border:1 solid">四</td>
<td style="border:1 solid">五</td>
<td style="border:1 solid">六</td>
</tr>
<tr height="4"><td colspan="7"></td></tr>
<% for(int j=0;j<6;j++) {//共5行 %>
<tr>
<% for(int i=j*7;i<(j+1)*7;i++) { //每行有7列 if((i-firstIndex+1)==today){//如果是这一天, 高亮显示 %>
<td width="30" height="23" align="center" bgcolor="gray" style="border:1 solid">
<font color="#FFFFFF"><b><%=days[i]%></b></font>
</td>
<% }else{ %>
<td width="10" height="23" align="center" style="border:1 solid"><%=days[i]%></td>
<% } }%>
</tr>
<% } %>
</table>
</body>
</html>