java获取不同时间的工具类
来源:互联网 发布:sql注入防范 编辑:程序博客网 时间:2024/06/05 02:35
// @author // 计算本周 上周 前三月 今年 去年 的时间段 // 组装时间 用于计算同比和环比的private Map<String, Object> getcurrlastweek(Map<String, Object> map){ String isdata = (String) map.get("range"); boolean bool = false; if(StringUtil.isBlank(isdata)|| "all".equals(isdata)){ return map; } Calendar cal = Calendar.getInstance(Locale.CHINA); Calendar cal2 = Calendar.getInstance(Locale.CHINA); //n为推迟的周数,1本周,-1向前推迟一周,2下周,依次类推 int n = 1; String monday = null; String sunday = null; String yearbegin = null; String yearend = null; switch(isdata){ case "thisWeek": bool = true; cal.setFirstDayOfWeek(Calendar.MONDAY); cal.add(Calendar.DATE, -1*7); //当前时间,貌似多余,其实是为了所有可能的系统一致 cal.setTimeInMillis(System.currentTimeMillis()); //想周几,这里就传几Calendar.MONDAY(TUESDAY...) cal.set(Calendar.DAY_OF_WEEK,Calendar.MONDAY); monday = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime()); cal2.setTime(cal.getTime()); cal2.add(Calendar.YEAR, -1); yearbegin = new SimpleDateFormat("yyyy-MM-dd").format(cal2.getTime()); cal.set(Calendar.DAY_OF_WEEK,Calendar.SUNDAY); sunday = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime()); cal.add(Calendar.YEAR, -1); yearend = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime()); break; case "lastWeek" : bool = true; cal.setFirstDayOfWeek(Calendar.MONDAY); cal.add(Calendar.DATE, -2*7); //当前时间,貌似多余,其实是为了所有可能的系统一致 cal.setTimeInMillis(System.currentTimeMillis()); cal.set(Calendar.DAY_OF_WEEK,Calendar.MONDAY); monday = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime()); cal2.setTime(cal.getTime()); cal2.add(Calendar.YEAR, -1); yearbegin = new SimpleDateFormat("yyyy-MM-dd").format(cal2.getTime()); cal.set(Calendar.DAY_OF_WEEK,Calendar.SUNDAY); sunday = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime()); cal.add(Calendar.YEAR, -1); yearend = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime()); break ; case "lastMonth": cal.setTimeInMillis(System.currentTimeMillis()); int month = cal.get(Calendar.MONTH); cal.set(Calendar.MONTH, month-2); cal.set(Calendar.DAY_OF_MONTH,cal.getActualMaximum(Calendar.DAY_OF_MONTH)); sunday= new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime()); cal2.setTime(cal.getTime()); cal2.add(Calendar.YEAR, -1); yearend= new SimpleDateFormat("yyyy-MM-dd").format(cal2.getTime()); cal.set(Calendar.DAY_OF_MONTH,cal.getActualMinimum(Calendar.DAY_OF_MONTH)); monday= new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime()); cal.add(Calendar.YEAR, -1); yearbegin = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime()); break; case "lastThreeMonth": cal.setTimeInMillis(System.currentTimeMillis()); int month2 = cal.get(Calendar.MONTH); cal.set(Calendar.MONTH, month2-6); cal.set(Calendar.DAY_OF_MONTH,cal.getActualMinimum(Calendar.DAY_OF_MONTH)); monday= new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime()); cal2.setTime(cal.getTime()); cal2.add(Calendar.YEAR, -1); yearbegin = new SimpleDateFormat("yyyy-MM-dd").format(cal2.getTime()); int month3 = cal.get(Calendar.MONTH); cal.set(Calendar.DAY_OF_MONTH,cal.getActualMaximum(Calendar.DAY_OF_MONTH)); cal.set(Calendar.MONTH, month3+3); sunday= new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime()); cal.add(Calendar.YEAR, -1); yearend = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime()); break; case "thisYear": int currentYear = cal.get(Calendar.YEAR)-1; cal.clear(); cal.set(Calendar.YEAR, currentYear); Date currYearFirst = cal.getTime(); monday= new SimpleDateFormat("yyyy-MM-dd").format(currYearFirst); cal2.setTime(cal.getTime()); cal2.add(Calendar.YEAR, -1); // yearbegin = new SimpleDateFormat("yyyy-MM-dd").format(cal2.getTime()); yearbegin = monday; cal.clear(); cal.set(Calendar.YEAR, currentYear); cal.roll(Calendar.DAY_OF_YEAR, -1); Date currYearLast = cal.getTime(); sunday = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime()); cal.add(Calendar.YEAR, -1); // yearend = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime()); yearend = sunday; break; default: break; }
0 0
- java获取不同时间的工具类
- java后台获取不同时间的方法
- java获取不同时区的时间字符串
- Java获取时间 时间计算 转换时间工具类
- java获取各种时间 工具类
- java中获取不同时间格式的方法
- java中获取不同时间格式的方法
- java中获取不同时间格式的方法
- 获取不同地区的时间
- 获取不同精度的时间
- Java生成随机数工具类,进制之间的转换工具类,获取指定时间,时间格式转换工具类
- Java生成随机数工具类,进制之间的转换工具类,获取指定时间,时间格式转换工具类
- java中获取不同时间格式的方法!及时间戳转化为时间格式
- JAVA 时间差距,两个时间相差多少天,时,分,秒;获取当天时间零点;获取及天钱的时间 (时间工具类)
- 一个获取各种时间的工具类
- android 获取时间的工具类
- 获取时间的java类
- JAVA中常使用的获取时间方法和设置不同时间
- web项目中不适用于java.sql.DriverManager描述的JDBC 4.0 Drivers及以后版本连接数据库是不需要用forName()?
- android实现多图片放大缩小的切换
- bwlabel函数
- DWR实例浅析
- Animation
- java获取不同时间的工具类
- 7.learningAction(行为库)2
- 网络编程-实验1-C与S通信
- Spring 学习2--Spring特殊语义注释类定义bean
- 测试博客
- Java异常
- 基于Primeton ESB的高可用MQ集群配置
- C# Keycode对照表
- 鼠标滚轮兼容火狐,