纯Java周历的写法
类别: JAVA教程
import java.util.*;
import com.unigroup2000.Global;
import java.io.*;
import javax.servlet.http.*;
import java.text.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class WeekCalendar {
public WeekCalendar() throws IOException{
}
public Calendar CalendarSetTime(String sCurrDate){
Calendar oCalendar = Calendar.getInstance();
Date oDate = new Date();
SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd");
if(!sCurrDate.equals("")&&sCurrDate!=null){
try{
oCalendar.setTime(sdf.parse(sCurrDate));
}catch(Exception ex){
ex.printStackTrace(System.err);
System.out.println("日期格式转换错误:="+sCurrDate );
}
}
else
oCalendar.setTime(oDate);
return oCalendar;
}
public List Calendar(HttpServletRequest request ,HttpServletResponse response,String sCurrDate){
String[] oneWeekDay={"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
Calendar oCal=null;
String LoopDate="",Flag="";
int iweek=0,iCurrWeek=0;
Date oDate = new Date();
oCal=CalendarSetTime(sCurrDate);//设置时间
iweek=oCal.get(Calendar.DAY_OF_WEEK)-1;
HashMap oHashMap=new HashMap();;
String DataSet[]= null;
List DayAndWeek = new ArrayList();
for(int i=iweek;i>0;i--){
oCal.add(Calendar.DATE,-i);
LoopDate=oCal.get(Calendar.YEAR)+"-"+(oCal.get(Calendar.MONTH)+1)+"-"+oCal.get(Calendar.DATE);
oCal=CalendarSetTime(sCurrDate);//重置时间
DataSet = new String[2];
DataSet[0]=LoopDate;
DataSet[1]=oneWeekDay[(iCurrWeek++)];
DayAndWeek.add(DataSet);
}
for(int i=0;i<7-iweek;i++){
oCal.add(Calendar.DATE,i);
LoopDate=oCal.get(Calendar.YEAR)+"-"+(oCal.get(Calendar.MONTH)+1)+"-"+oCal.get(Calendar.DATE);
oCal=CalendarSetTime(sCurrDate);
DataSet = new String[2];
DataSet[0]=LoopDate;
DataSet[1]=oneWeekDay[(iCurrWeek++)];
DayAndWeek.add(DataSet);
}
return DayAndWeek;
}
import com.unigroup2000.Global;
import java.io.*;
import javax.servlet.http.*;
import java.text.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class WeekCalendar {
public WeekCalendar() throws IOException{
}
public Calendar CalendarSetTime(String sCurrDate){
Calendar oCalendar = Calendar.getInstance();
Date oDate = new Date();
SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd");
if(!sCurrDate.equals("")&&sCurrDate!=null){
try{
oCalendar.setTime(sdf.parse(sCurrDate));
}catch(Exception ex){
ex.printStackTrace(System.err);
System.out.println("日期格式转换错误:="+sCurrDate );
}
}
else
oCalendar.setTime(oDate);
return oCalendar;
}
public List Calendar(HttpServletRequest request ,HttpServletResponse response,String sCurrDate){
String[] oneWeekDay={"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
Calendar oCal=null;
String LoopDate="",Flag="";
int iweek=0,iCurrWeek=0;
Date oDate = new Date();
oCal=CalendarSetTime(sCurrDate);//设置时间
iweek=oCal.get(Calendar.DAY_OF_WEEK)-1;
HashMap oHashMap=new HashMap();;
String DataSet[]= null;
List DayAndWeek = new ArrayList();
for(int i=iweek;i>0;i--){
oCal.add(Calendar.DATE,-i);
LoopDate=oCal.get(Calendar.YEAR)+"-"+(oCal.get(Calendar.MONTH)+1)+"-"+oCal.get(Calendar.DATE);
oCal=CalendarSetTime(sCurrDate);//重置时间
DataSet = new String[2];
DataSet[0]=LoopDate;
DataSet[1]=oneWeekDay[(iCurrWeek++)];
DayAndWeek.add(DataSet);
}
for(int i=0;i<7-iweek;i++){
oCal.add(Calendar.DATE,i);
LoopDate=oCal.get(Calendar.YEAR)+"-"+(oCal.get(Calendar.MONTH)+1)+"-"+oCal.get(Calendar.DATE);
oCal=CalendarSetTime(sCurrDate);
DataSet = new String[2];
DataSet[0]=LoopDate;
DataSet[1]=oneWeekDay[(iCurrWeek++)];
DayAndWeek.add(DataSet);
}
return DayAndWeek;
}
-= 资 源 教 程 =-
文 章 搜 索