以下為java代碼:
<%@ page import= "java.text.SimpleDateFormat"%>
<%@ page import= "java.util.Calendar"%>
public int use(int reyear, int remonth) {
Calendar now = Calendar.getInstance(); // 實(shí)例化Calendar
int week_num;
now.set(reyear, remonth, 1); // 設(shè)置時(shí)間為所要查詢(xún)的年月的第一天
week_num = (int) (now.get(Calendar.DAY_OF_WEEK));// 得到第一天的星期
return week_num;
}
Calendar now = Calendar.getInstance(); // 實(shí)例化Calendar
int year, month_num, first_day_num;
String log[] = { "日", "一", "二", "三", "四", "五", "六" };
month_num = (int) (now.get(Calendar.MONTH)); // 得到當(dāng)前時(shí)間的月份
year = (int) (now.get(Calendar.YEAR)); // 得到當(dāng)前時(shí)間的年份
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; // 存儲(chǔ)月份的天數(shù)
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); // 前個(gè)月
month_day_score = cal.getActualMaximum(Calendar.DAY_OF_MONTH);// 最后一天
int NowDay=1;
for (int i = 0; i <6; i++) { // 初始化標(biāo)簽%>
<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>
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者