| | |
| | | public static DateTimeFormatter format_ymdhms = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
| | | public static DateTimeFormatter format_ymd = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
| | | public static DateTimeFormatter format_ymdhms_string = DateTimeFormatter.ofPattern("yyyyMMddHHmmss"); |
| | | public static DateTimeFormatter format_ymdhms_yyyyMMddmmHHssSSS = DateTimeFormatter.ofPattern("yyyyMMddmmHHssSSS"); |
| | | public static DateTimeFormatter format_ymdhms_no_signal = DateTimeFormatter.ofPattern("yyyyMMddHHmmss"); |
| | | public static SimpleDateFormat yyyyMMdd_format = new SimpleDateFormat("yyyy-MM-dd"); |
| | | public static SimpleDateFormat yyyy_MM_dd_format = new SimpleDateFormat("yyyy/MM/ddHH:mm:ss"); |
| | |
| | | } |
| | | |
| | | public static void main(String[] args) throws Exception { |
| | | Date date= getLastMonthFirst(); |
| | | Date after = getLastMonthEnd(); |
| | | System.out.println(date); |
| | | System.out.println(after); |
| | | System.out.println(getMonthTwentyDay()); |
| | | // List<String> beforeDays = getBeforeDays(15); |
| | | // System.out.println(beforeDays); |
| | | List<String> yearMonths = getYearMonths(); |
| | | System.out.println(yearMonths); |
| | | List<String> latest12Month = getLatest12Month(LocalDate.now(), 10); |
| | | System.out.println(latest12Month); |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | /** |
| | | * 获取之前的日期 |
| | | * |
| | | * @return |
| | | */ |
| | | public static String getBeforeDay(Integer amount) { |
| | | Calendar cal = Calendar.getInstance(); |
| | | cal.setTime(new Date()); |
| | | cal.add(Calendar.DATE, -amount); |
| | | return DateUtil.format(cal.getTime(),"yyyy-MM-dd"); |
| | | } |
| | | |
| | | /** |
| | | * 获取最近本月20天数据 |
| | | * |
| | | * @return |
| | |
| | | } |
| | | |
| | | } |
| | | |
| | | public static List<String> getBeforeDays(int before) { |
| | | List<String> dates = new ArrayList<>(); |
| | | for (int i = before; i >= 0; i--) { |
| | | dates.add(getBeforeDay(i)); |
| | | } |
| | | return dates; |
| | | } |
| | | |
| | | /** |
| | | * 获取当年所有月份 |
| | | * |
| | | * @return |
| | | */ |
| | | public static List<String> getYearMonths() { |
| | | Calendar instance = Calendar.getInstance(); |
| | | int year = instance.get(Calendar.YEAR); |
| | | List<String> months = new ArrayList<>(); |
| | | for (int i = 1; i <= 12; i++) { |
| | | String result = String.valueOf(year); |
| | | if (i < 10) { |
| | | result = result + "-0" +i; |
| | | } else { |
| | | result = result + "-"+i; |
| | | } |
| | | months.add(result); |
| | | } |
| | | return months; |
| | | } |
| | | |
| | | //获取当前12个月 |
| | | public static List<String> getLatest12Month(LocalDate date,int num){ |
| | | List<String> monthList = new ArrayList<>(); |
| | | for(int i = 0;i <= num-1; i++){ |
| | | LocalDate localDate = date.minusMonths(i); |
| | | String month = localDate.toString().substring(0,7); |
| | | monthList.add(month); |
| | | } |
| | | return monthList; |
| | | } |
| | | |
| | | |
| | | } |