| | |
| | | return dt1; |
| | | } |
| | | |
| | | |
| | | public static List<Date> getDateList(Date dBegin, Date dEnd) { |
| | | int i = 1; |
| | | //日期工具类准备 |
| | | DateFormat format = new SimpleDateFormat("yyyy-MM-dd"); |
| | | //设置开始时间 |
| | | Calendar calBegin = Calendar.getInstance(); |
| | | calBegin.setTime(dBegin); |
| | | int weekNumber = calBegin.get(Calendar.DAY_OF_WEEK) - 1; |
| | | //设置结束时间 |
| | | Calendar calEnd = Calendar.getInstance(); |
| | | calEnd.setTime(dEnd); |
| | | //装返回的日期集合容器 |
| | | List<Date> dateList = new ArrayList<Date>(); |
| | | dateList.add(dBegin); |
| | | //将第一个月添加里面去 |
| | | while (dEnd.after(calBegin.getTime())) { |
| | | calBegin.add(Calendar.DAY_OF_MONTH, 1); |
| | | Date date = calBegin.getTime(); |
| | | dateList.add(date); |
| | | } |
| | | return dateList; |
| | | } |
| | | |
| | | |
| | | |
| | | public static Date StringToDateFormat(String DATE,String format) { |
| | | if(StringUtils.isBlank(DATE)){ |
| | | return null; |
| | | } |
| | | DateFormat df = new SimpleDateFormat(format); |
| | | Date dt1 = null; |
| | | try { |
| | | dt1 = df.parse(DATE); |
| | | } catch (Exception exception) { |
| | | exception.printStackTrace(); |
| | | } |
| | | return dt1; |
| | | } |
| | | |
| | | |
| | | public static String getXDaysAfter(Date date, Integer days){ |
| | | Timestamp currentTimestamp = new Timestamp(date.getTime()); |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(currentTimestamp); |
| | | calendar.add(Calendar.DAY_OF_YEAR, days-1); // 在当前时间基础上添加指定的天数 |
| | | calendar.add(Calendar.DAY_OF_YEAR, days); // 在当前时间基础上添加指定的天数 |
| | | SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); |
| | | return formatter.format(calendar.getTime()); |
| | | } |
| | |
| | | /** |
| | | * 得出两个日期之间的间隔天数 |
| | | * |
| | | * @param strFromDate |
| | | * @param smallDate |
| | | * 格式为yyyy-MM-dd |
| | | * @param strToDate |
| | | * @param bigDate |
| | | * 格式为yyyy-MM-dd |
| | | * @return int |
| | | */ |
| | | public static long getBetweenDays(String strFromDate, String strToDate) { |
| | | public static long getBetweenDays(String smallDate, String bigDate) { |
| | | long m_intervalday = 0;// 初始化时间间隔的值为0 |
| | | // 使用的时间格式为yyyy-MM-dd |
| | | SimpleDateFormat m_simpledateformat = new SimpleDateFormat("yyyy-MM-dd"); |
| | | try { |
| | | Date fromDate = m_simpledateformat.parse(strFromDate); |
| | | Date toDate = m_simpledateformat.parse(strToDate); |
| | | Date fromDate = m_simpledateformat.parse(smallDate); |
| | | Date toDate = m_simpledateformat.parse(bigDate); |
| | | m_intervalday = toDate.getTime() - fromDate.getTime();// 计算所得为微秒数 |
| | | m_intervalday = m_intervalday / 1000 / 60 / 60 / 24;// 计算所得的天数 |
| | | |
| | |
| | | |
| | | public static void main(String[] args) { |
| | | try { |
| | | System.out.println((int)(3.222)); |
| | | |
| | | System.out.println(DateUtil.getCurrDate()); |
| | | } catch (Exception ex) { |
| | | ex.printStackTrace(); |
| | | } |