以下为java代码:
<%@ page import= "java.text.SimpleDateFormat"%>
<%@ page import= "java.util.Calendar"%>
public int use(int reyear, int remonth) {
Calendar now = Calendar.getInstance(); // 实例化Calendar
int week_num;
now.set(reyear, remonth, 1); // 设置时间为所要查询的年月的第一天
week_num = (int) (now.get(Calendar.DAY_OF_WEEK));// 得到第一天的星期
return week_num;
}
Calendar now = Calendar.getInstance(); // 实例化Calendar
int year, month_num, first_day_num;
String log[] = { "日", "一", "二", "三", "四", "五", "六" };
month_num = (int) (now.get(Calendar.MONTH)); // 得到当前时间的月份
year = (int) (now.get(Calendar.YEAR)); // 得到当前时间的年份
first_day_num = use(year, month_num);
以下为jsp代码:
<table>
<thead>
<tr><td>日</td><td>一</td><td>二</td><td>三</td><td>四</td><td>五</td><td>六</td></tr>
</thead>
<tbody>
<%
int month_day_score; // 存储月份的天数
int count;
month_day_score = 0;
count = 1;
java.util.Date date = new java.util.Date(year, month_num + 1, 1); // now
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.add(Calendar.MONTH, -1); // 前个月
month_day_score = cal.getActualMaximum(Calendar.DAY_OF_MONTH);// 最后一天
int NowDay=1;
for (int i = 0; i <6; i++) { // 初始化标签%>
<tr>
<%
for (int j = 0; j <7; j++) {
String nowdate = year+"";
if((month_num+1)<10){
nowdate=nowdate+"-"+"0"+(month_num + 1);
}else{
nowdate=nowdate+"-"+(month_num + 1);
}
if(NowDay<10){
nowdate=nowdate+"-"+"0"+NowDay;
}else{
nowdate=nowdate+"-"+NowDay;
}
if(i==0&&(j+1)<first_day_num){
%>
<td date-month="" date-day=""></td>
<%
}else{
if(NowDay<(month_day_score)+1){
String sign_sql="select count(1) from integraldetail where intime like '%"+nowdate+"%' and uid='"+UID+"' and `remark`='签到' and iid=1 limit 1";
int exe1 = db.executeCounts(sign_sql);
//class="current-day" 为选中效果样式
%>
<td date-month="<%=(month_num+1)%>" <% if(exe1>0) {%>class="current-day"<%}%> date-day="<%=NowDay%>"><%=NowDay%></td>
<%
}else{
%>
<td date-month="" date-day=""></td>
<%
}
NowDay++;
}
}%>
</tr>
<%}%>
</tbody>
</table>