根据开始和结束时间,计算出该时间段每个星期的开始和结束时间
2015-07-03 15:47
375 查看
/***
* 根据开始和结束时间,计算出该时间段每个星期的开始和结束时间
* @return 时间段内的开始和结束时间List
* */
public List<String> getWeekByTime(String startDate,String endDate){
Calendar c_begin = new GregorianCalendar();
Calendar c_end = new GregorianCalendar();
DateFormatSymbols dfs = new DateFormatSymbols();
List<String> timeList = new ArrayList<String>();
c_begin.set(Integer.parseInt(startDate.split("-")[0]), Integer.parseInt(startDate.split("-")[1])-1, Integer.parseInt(startDate.split("-")[2])-1); //Calendar的月从0-11,所以4月是3.
c_end.set(Integer.parseInt(endDate.split("-")[0]), Integer.parseInt(endDate.split("-")[1])-1, Integer.parseInt(endDate.split("-")[2])-1); //Calendar的月从0-11,所以5月是4.
int count = 1;
c_end.add(Calendar.DAY_OF_YEAR, 1); //结束日期下滚一天是为了包含最后一天
int startWeek=0;
int endWeek=0;
String startTime="";
String endTime="";
while(c_begin.before(c_end)){
if(count==1){
if(c_begin.get(Calendar.DAY_OF_WEEK)==1){
timeList.add(startDate+"&"+new java.sql.Date(c_begin.getTime().getTime())+"");
}
}else{
if(c_begin.get(Calendar.DAY_OF_WEEK)==2){
startWeek=count;
startTime=new java.sql.Date(c_begin.getTime().getTime())+"";
}
if(c_begin.get(Calendar.DAY_OF_WEEK)==1){
endWeek=count;
endTime=new java.sql.Date(c_begin.getTime().getTime())+"";
}
if(startWeek==endWeek){
timeList.add(startTime+"&"+endTime+"&"+"第"+count+"周 ");
}
}
if(c_begin.get(Calendar.DAY_OF_WEEK)==Calendar.SUNDAY){
count++;
}
c_begin.add(Calendar.DAY_OF_YEAR, 1);
}
return timeList;
}
* 根据开始和结束时间,计算出该时间段每个星期的开始和结束时间
* @return 时间段内的开始和结束时间List
* */
public List<String> getWeekByTime(String startDate,String endDate){
Calendar c_begin = new GregorianCalendar();
Calendar c_end = new GregorianCalendar();
DateFormatSymbols dfs = new DateFormatSymbols();
List<String> timeList = new ArrayList<String>();
c_begin.set(Integer.parseInt(startDate.split("-")[0]), Integer.parseInt(startDate.split("-")[1])-1, Integer.parseInt(startDate.split("-")[2])-1); //Calendar的月从0-11,所以4月是3.
c_end.set(Integer.parseInt(endDate.split("-")[0]), Integer.parseInt(endDate.split("-")[1])-1, Integer.parseInt(endDate.split("-")[2])-1); //Calendar的月从0-11,所以5月是4.
int count = 1;
c_end.add(Calendar.DAY_OF_YEAR, 1); //结束日期下滚一天是为了包含最后一天
int startWeek=0;
int endWeek=0;
String startTime="";
String endTime="";
while(c_begin.before(c_end)){
if(count==1){
if(c_begin.get(Calendar.DAY_OF_WEEK)==1){
timeList.add(startDate+"&"+new java.sql.Date(c_begin.getTime().getTime())+"");
}
}else{
if(c_begin.get(Calendar.DAY_OF_WEEK)==2){
startWeek=count;
startTime=new java.sql.Date(c_begin.getTime().getTime())+"";
}
if(c_begin.get(Calendar.DAY_OF_WEEK)==1){
endWeek=count;
endTime=new java.sql.Date(c_begin.getTime().getTime())+"";
}
if(startWeek==endWeek){
timeList.add(startTime+"&"+endTime+"&"+"第"+count+"周 ");
}
}
if(c_begin.get(Calendar.DAY_OF_WEEK)==Calendar.SUNDAY){
count++;
}
c_begin.add(Calendar.DAY_OF_YEAR, 1);
}
return timeList;
}
相关文章推荐
- RTP解包
- leetcode | Path Sum
- warning C4819: The file contains a character that cannot be represented in the current code page (93
- 最小二乘法多项式拟合的Java实现
- CocoaPods
- JS 前端框架6 AngularJS 入门使用
- hadoop streaming -archives 解压jar、zip、tar.gz的验证
- android添加背景音乐
- HTTP_1_Web及网络基础
- 使用maven构建springmvc-mybatis项目
- Unity中Shader的个人理解
- No architectures to compile for (ONLY_ACTIVE_ARCH=YES, active arch=arm64, VALID_ARCHS=armv7 armv7s).
- 解析字典包含关键字比如ID,description等,MJExtension 框架 不能直接设置变量与其同名。
- POJ-1703-Find them, Catch them
- 音乐播放器
- java基础知识随笔--流程控制
- Mysql连接数据库的操作
- Android背景音乐开关示例
- 基于google.zxing的二维码java 代码
- error C2440: ’static_cast’ : cannot convert from ‘UINT (__thiscall CStaticLink::* )(CPoint)’ to ‘LRE