计算两个日期之间的周
2015-10-13 13:54
253 查看
public void getDays() {
Calendar c_begin = new GregorianCalendar();
Calendar c_end = new GregorianCalendar();
DateFormatSymbols dfs = new DateFormatSymbols();
String[] weeks = dfs.getWeekdays();
c_begin.set(2015, 8, 2); // Calendar的月从0-11,所以4月是3.
c_end.set(2015, 9, 20); // Calendar的月从0-11,所以5月是4.
int count = 1;
c_end.add(Calendar.DAY_OF_YEAR, 1); // 结束日期下滚一天是为了包含最后一天
while (c_begin.before(c_end)) {
System.out.println("第" + count + "周 日期:"
+ new Date(c_begin.getTime().getTime()) + ","
+ weeks[c_begin.get(Calendar.DAY_OF_WEEK)]);
if (c_begin.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
count++;
}
c_begin.add(Calendar.DAY_OF_YEAR, 1);
}
}
Calendar c_begin = new GregorianCalendar();
Calendar c_end = new GregorianCalendar();
DateFormatSymbols dfs = new DateFormatSymbols();
String[] weeks = dfs.getWeekdays();
c_begin.set(2015, 8, 2); // Calendar的月从0-11,所以4月是3.
c_end.set(2015, 9, 20); // Calendar的月从0-11,所以5月是4.
int count = 1;
c_end.add(Calendar.DAY_OF_YEAR, 1); // 结束日期下滚一天是为了包含最后一天
while (c_begin.before(c_end)) {
System.out.println("第" + count + "周 日期:"
+ new Date(c_begin.getTime().getTime()) + ","
+ weeks[c_begin.get(Calendar.DAY_OF_WEEK)]);
if (c_begin.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
count++;
}
c_begin.add(Calendar.DAY_OF_YEAR, 1);
}
}
相关文章推荐
- HTTP Cookie深入理解
- c# base64 编码解码
- 安卓开发中的工作笔记
- c#使用Socket获取网页(含自动跳转, 解压网页)
- 10 种机器学习算法的要点
- c#使用Socket获取网页(含自动跳转, 解压网页)
- 对于view的深入理解,续篇(一)重写ViewGroup的onDraw
- 如何解决http请求304问题,304的原因很可能是缓存造成的。
- iOS开发系列--音频播放、录音、视频播放、拍照、视频录制
- iOS9 HTTP 不能正常使用的解决办法
- linux内核配置与裁剪浅析
- [置顶] 关于离线安装genymotion时出现的错误的解决办法
- C# Socket 实现的淘宝秒杀器(抢拍器)
- 部署ntp时间服务器
- CSS中height和width在IE和其他浏览器中的区别图文详解
- C# Socket 实现的淘宝秒杀器(抢拍器)
- ZOJ 3232 - It's not Floyd Algorithm(强连通缩点+Floyd)
- Mysql创建存储过程时,出现ERROR 1064 (42000):的原因的一种
- voc-release5 windows下的编译
- android--(Fragments)