打算要做一个工作总结平台,考虑到要实现周工作总结的功能就得先把一年先按某周某周区分开来,查了查Api
采用了calendar类,并把最后分的结果传到数据库,
year week content
2005 1 1月3日~1月9日
... ... ....................
源码如下(其中DB类是我用来实现数据库连接用的)
import java.util.*;
import java.util.Date;
import java.sql.*;
import rkind.db;
public class shijian {
public static void main(String args[]){
int day,mon,year,week,dayofweek;
db base=new db();
String content="";
Calendar nova = Calendar.getInstance();
Date d1=new Date();
nova.setTime(d1);
nova.set(2005,Calendar.JANUARY,1);
//nova.add(Calendar.DATE,6);
//day=nova.get(Calendar.WEEK_OF_YEAR );
dayofweek=nova.get(Calendar.DAY_OF_WEEK );
while(dayofweek!=2){
nova.add(Calendar.DATE,1);
dayofweek=nova.get(Calendar.DAY_OF_WEEK );
}
year=nova.get(Calendar.YEAR);
//String sql=new String("insert into shijian(year,week,content) values('"+year+"','"+week+"','"+content+"')");
//System.out.println("day+++:"+day);
while(year==2005){
week=nova.get(Calendar.WEEK_OF_YEAR );
mon=nova.get(Calendar.MONTH)+1;
day=nova.get(Calendar.DATE);
content=mon+"月"+day+"日"+"~~ ";
System.out.print("第"+week+"周"+": "+mon+"月"+day+"日");
nova.add(Calendar.DATE,6);
week=nova.get(Calendar.WEEK_OF_YEAR );
mon=nova.get(Calendar.MONTH)+1;
day=nova.get(Calendar.DATE);
content+=mon+"月"+day+"日";
try{
String sql=new String("insert into shijian(year,week,content) values('"+year+"','"+week+"','"+content+"')");
base.executeUpdate(sql);
}catch(Exception e){System.out.println(e);}
System.out.println("~~~~"+mon+"月"+day+"日");
nova.add(Calendar.DATE,1);
week=nova.get(Calendar.WEEK_OF_YEAR );
mon=nova.get(Calendar.MONTH)+1;
day=nova.get(Calendar.DATE);
year=nova.get(Calendar.YEAR);
}
}
}
虽然功能上实现了,但是还有大量的重复代码,和费语句,这就是没有好好重视J2se的结果,没办法,
边学J2EE边看Se吧,:)
posted on 2005-10-27 13:05
rkind 阅读(180)
评论(0) 编辑 收藏 所属分类:
JAVA基础&数据库