|
一个尚待修改的日历类
[PHP]
/*
* GetCal.java
*
* Created on 2005年3月7日, 上午9:22
*/
package com.sdate;
import java.util.*;
/**
*
* @author tony
*/
public class GetCal {
String days[];
String strCal;
/** Creates a new instance of getcal */
public GetCal() {
days=new String[42];
for(int i=0;i<42;i++){
days="";
}
}
public String getcalstr(String filename, int mon){
int mont;
GregorianCalendar currentDay = new GregorianCalendar();
int today=currentDay.get(Calendar.DAY_OF_MONTH);
int month=currentDay.get(Calendar.MONTH);
int year= currentDay.get(Calendar.YEAR);
strCal = new String("当前日期:" + year+"年"+ (month+1)+"月"+today+"日");
Calendar thisMonth=Calendar.getInstance();
if(month-mon >= 0 && month-mon <12){
thisMonth.set(Calendar.MONTH, month-mon );
mont = month+1-mon;
}else{
thisMonth.set(Calendar.MONTH, month );
mont = month+1;
}
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);
for(int i=0;i<maxIndex;i++)
{
days[firstIndex+i]=String.valueOf(i+1);
}
strCal = new String(strCal + "<table border=\"0\" width=\"200\" height=\"81\">");
strCal = new String(strCal + "<div align=center>");
strCal = new String(strCal + "<tr>");
strCal = new String(strCal + "<th colspan='7'>");
strCal = new String(strCal+ "<a href='"+filename+"?mon="+ (mon - 1) +"'><<</a> " + mont +"月" +" <a href='"+filename+"?mon="+ (mon + 1) +"'>>></a>");
strCal = new String(strCal + "</th>");
strCal = new String(strCal + "</tr>");
strCal = new String(strCal + "<tr>");
strCal = new String(strCal + "<th width=\"25\" height=\"16\" ><font color=\"red\">日</font></th>");
strCal = new String(strCal + "<th width=\"25\" height=\"16\" >一</th>");
strCal = new String(strCal + "<th width=\"25\" height=\"16\" >二</th>");
strCal = new String(strCal + "<th width=\"25\" height=\"16\" >三</th>");
strCal = new String(strCal + "<th width=\"25\" height=\"16\" >四</th>");
strCal = new String(strCal + "<th width=\"25\" height=\"16\" >五</th>");
strCal = new String(strCal + "<th width=\"25\" height=\"16\" ><font color=\"red\">六</font></th>");
strCal = new String(strCal + "</tr>");
for(int j=0;j<6;j++) {
strCal = new String(strCal + "<tr>");
for(int i=j*7;i<(j+1)*7;i++) {
strCal = new String(strCal + "<td width=\"15%\" height=\"16\" valign=\"middle\" align=\"center\">");
if((i-firstIndex+1)==today){
strCal = new String(strCal + "<a href=''><font color=\"red\">"+ days+"</font></a>");
}else{
strCal = new String(strCal + "<a href=''>" + days + "</a>");
}
strCal = new String(strCal + "</td>");
}
strCal = new String(strCal + "</tr>");
}
strCal = new String(strCal + "</div></table> ");
return strCal;
}
}
[/PHP] |
|