//获取前月的第一天
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
//获取当前月第一天:
Calendar c = Calendar.getInstance(); String first = null;//第一天
String last = null;//第二天
//判断获取的参数如果为-1
if(month.equals("-1")){
c.add(Calendar.MONTH, -1);
c.set(Calendar.DAY_OF_MONTH,1);//设置为1号,当前日期既为本月第一天
first = sdf.format(c.getTime()); //获取上月的最后一天
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.DAY_OF_MONTH, 1);
calendar.add(Calendar.DATE, -1);
last = sdf.format(calendar.getTime());
}else{
c.add(Calendar.MONTH, 0);
c.set(Calendar.DAY_OF_MONTH,1);//设置为1号,当前日期既为本月第一天
first = sdf.format(c.getTime()); //获取当前月最后一天
Calendar ca = Calendar.getInstance();
ca.set(Calendar.DAY_OF_MONTH, ca.getActualMaximum(Calendar.DAY_OF_MONTH));
last = sdf.format(ca.getTime());
} //循环时间段
Date startDate = sdf.parse(first); Date endDate = sdf.parse(last); Calendar start = Calendar.getInstance();
start.setTime(startDate);
Long statTime = start.getTimeInMillis(); Calendar end = Calendar.getInstance();
end.setTime(endDate);
Long endTime = end.getTimeInMillis(); Long oneDay = 1000 * 60 * 60 * 24l; Long time = statTime; List timeList=new ArrayList();
while (time <= endTime) {
Date d = new Date(time);
DateFormat df = new SimpleDateFormat("yyyy/MM/dd");
time += oneDay;
timeList.add(df.format(d));
} //根据渠道ID查询当前代理公司下有多少交易成功的单 String lastDate = null;
if(month.equals("-1")){
//获取这个时间段下一天
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.DAY_OF_MONTH, 1);
calendar.add(Calendar.DATE, 0);
lastDate = sdf.format(calendar.getTime());
}else{
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.DAY_OF_MONTH, 1);
calendar.add(Calendar.MONTH, 1);
lastDate = sdf.format(calendar.getTime());
}

这是获取时间,然后这个时间进行相加

比如

updateDate  = "2016-11-9"
//得到保单状态最后修改的时间
Date updateDate = tranCar.getDtUpdateDate();
//计算时间,+3天
Calendar calendar = Calendar.getInstance();
calendar.setTime(updateDate);
calendar.add(calendar.DATE,3);
//得出的结果
updateDate  = "2016-11-12"
//获取上个月25号的时间
private String setDayLastMonth(SimpleDateFormat format) {
Calendar month = Calendar.getInstance();
month.add(Calendar.MONTH,-1);
month.set(Calendar.DATE,25);
String oneDayLastMonth = format.format(month.getTime());
return oneDayLastMonth;
} //获取当月的时间,这里时间不能超过当月25号
private String setDayBefore(SimpleDateFormat format) {
Calendar cal = Calendar.getInstance();//获取一个日历
cal.add(Calendar.DAY_OF_MONTH, -1);//取当前日期的前一天. //当前时间
String today = format.format(Calendar.getInstance().getTime());
String theDayBefore = format.format(cal.getTime());
//比较时间大小
Date theDayBeforeDate = cal.getTime();//当前时间的前一天日期格式
Date todayDate = Calendar.getInstance().getTime();//当前时间日期格式 if(theDayBeforeDate.getTime() > todayDate.getTime()){
//默认日期只能为本月的24日
cal.set(Calendar.DATE,24);
theDayBefore = format.format(cal.getTime());
}
return theDayBefore;
}

最新文章

  1. form表单序列化后的数据转json对象
  2. 3.Java基础之Date对象
  3. .Net 4.5 的async 和await 的简单理解使用
  4. 使用staruml学习画类图
  5. 导出程序界面(UI)到图片
  6. Linux中常用的查看系统信息的命令
  7. 【No.1】监控Linux性能25个命令行工具
  8. Sequential Read Ahead For SQL Server
  9. 模拟QQ侧滑控件 实现三种界面切换效果(知识点:回调机制,解析网络json数据,fragment用法等)。
  10. php多文本框提交
  11. 10. leetcode 226 Invert Binary Tree
  12. [日常] AtCoder Beginner Contest 075 翻车实录
  13. go [第一篇]初识
  14. windows下安装bpython方法 (新)
  15. [daily] cscope
  16. Vue(二) 计算属性
  17. IAR EWARM 关闭纯汇编函数的警告的方法
  18. java 基本数据类型及自动类型提升
  19. Streamr助你掌控自己的数据
  20. MapReduce编程之Map Join多种应用场景与使用

热门文章

  1. Canvas绘制时钟
  2. win10 64位专业版系统中显示32位dcom组件配置的方法
  3. POI对Excel自定义日期格式的读取
  4. 第一章 Shiro简介——《跟我学Shiro》(转)
  5. Hive metastore三种配置方式
  6. Python中两种处理错误方法的比较
  7. Linux学习之八--关闭firewall防火墙安装iptables并配置
  8. Lisp永远成不了编程主流语言
  9. BZOJ2292——【POJ Challenge 】永远挑战
  10. cin的使用问题