| | |
| | | } |
| | | return list; |
| | | } |
| | | |
| | | |
| | | public static List<String> getBeforDaysByFormat(Date currentDate,Integer days,String format){ |
| | | SimpleDateFormat sdf = new SimpleDateFormat(format); |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(currentDate); |
| | | Date endDate = currentDate; // 获取当前日期 |
| | | calendar.add(Calendar.DAY_OF_YEAR, -days); // 往前推7天 |
| | | Date startDate = calendar.getTime(); // 获取推算后的日期 |
| | | List<String> list = new ArrayList<>(); |
| | | while (startDate.before(endDate)) { |
| | | calendar.add(Calendar.DAY_OF_YEAR, 1); // 获取下一天日期 |
| | | startDate = calendar.getTime(); |
| | | list.add(DateUtil.dateToString(startDate,format)); |
| | | System.out.println(DateUtil.dateToString(startDate,format)); |
| | | } |
| | | return list; |
| | | } |
| | | |
| | | public static List<Date> getDateListBeforDays(Date currentDate,Integer days){ |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
| | | Calendar calendar = Calendar.getInstance(); |
| | |
| | | */ |
| | | public static String getCurrDateTime() { |
| | | Timestamp date = new Timestamp(System.currentTimeMillis()); |
| | | SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); |
| | | SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | return formatter.format(date); |
| | | } |
| | | |