用户登录  |  用户注册
首 页商业源码原创产品编程论坛
当前位置:PB创新网文章中心Java

纯Java周历的写法

减小字体 增大字体 作者:佚名  来源:本站整理  发布时间:2009-03-16 18:54:27
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;
}



Tags:

作者:佚名

文章评论评论内容只代表网友观点,与本站立场无关!

   评论摘要(共 0 条,得分 0 分,平均 0 分) 查看完整评论

相关文章

PB创新网ourmis.com】Copyright © 2000-2009 . All Rights Reserved .
页面执行时间:11,656.25000 毫秒
Email:ourmis@126.com QQ:2322888 蜀ICP备05006790号