whyclxw
2 天以前 dbba9c3fc5187432c34329a2a18e07feca729de5
src/main/java/com/whyc/util/ActionUtil.java
@@ -17,9 +17,10 @@
import java.lang.reflect.Type;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.time.LocalDate;
import java.time.YearMonth;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.whyc.pojo.db_user.User;
@@ -28,6 +29,8 @@
   public static String time_yyyyMMddHHmmss = "yyyy-MM-dd HH:mm:ss";
   public static String time_yyyyMMdd = "yyyy-MM-dd";
   public static String time_yyyyMM = "yyyy-MM";
   public static String time_yyyy_MM = "yyyy_MM";
   public static String time_yyyyMMdd_HH_mm_ss = "yyyy-MM-dd_HH_mm_ss";
   public static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
   public static SimpleDateFormat sdfwithOutday = new SimpleDateFormat("yyyy_MM");
@@ -338,7 +341,6 @@
        cal.set(Calendar.DAY_OF_MONTH,day);  
        if(type==1){
           return   new   SimpleDateFormat( "yyyy-MM-dd ").format(cal.getTime())+"00:00:00";  
        } else if(type==2){
           return   new   SimpleDateFormat( "yyyy-MM-dd ").format(cal.getTime())+"09:00:00";  
        }else if(type==3){
@@ -417,8 +419,34 @@
        } else {//相等
            return 0;
        }
        }
    /**
   }
   //计算当前月的上一个季度年_月份集合
   public static List<String> getLastQuarterYearMonths() {
      LocalDate currentDate = LocalDate.now();
      int currentYear = currentDate.getYear();
      int currentMonth = currentDate.getMonthValue();
      int quarter = (currentMonth - 1) / 3 + 1; // 计算当前季度
      int lastQuarter = quarter - 1; // 上一季度
      if (lastQuarter == 0) {
         lastQuarter = 4; // 如果当前是第一季度,则上一季度为第四季度
      }
      List<String> yearMonths = new ArrayList<>();
      for (int i = 1; i <= 3; i++) {
         int month = (lastQuarter - 1) * 3 + i;
         int year = currentYear;
         // 如果上一季度是第四季度,则年份需要减一年
         if (lastQuarter == 4) {
            year = currentYear - 1;
         }
         yearMonths.add(year + "_" + (month < 10 ? "0" + month : month)); // 保证月份为两位格式
      }
      return yearMonths;
   }
   /**
     * @Description: 根据图片地址转换为base64编码字符串
     * @Author: 
     * @CreateTime: 
@@ -612,5 +640,45 @@
      }
      return lang;
   }
     //两时间之间的年月集合
   public static List<String> getDateListBetweenDates(Date startTime, Date endTime) {
      // 指定开始日期和结束日期
      LocalDate startDate = LocalDate.of(startTime.getYear() + 1900, startTime.getMonth() + 1, startTime.getDay()); // 示例起始日期
      LocalDate endDate = LocalDate.of(endTime.getYear() + 1900, endTime.getMonth() + 1, endTime.getDay());  // 示例结束日期
      List<String> dateList = new ArrayList<>();
      LocalDate currentDate = startDate;
      DateTimeFormatter formatter = DateTimeFormatter.ofPattern(ActionUtil.time_yyyy_MM);
      while (!currentDate.isAfter(endDate)) {
         String formattedDate = currentDate.format(formatter);
         dateList.add(formattedDate);
         currentDate = currentDate.plusMonths(1);
      }
      return dateList;
   }
   // 匹配 "_" 后跟一个字母(小写或大写)
   public static String toCamelCase(String input) {
      // 匹配 "_" 后跟一个字母(小写或大写)
      Pattern pattern = Pattern.compile("_(\\w)");
      Matcher matcher = pattern.matcher(input);
      StringBuffer result = new StringBuffer();
      while (matcher.find()) {
         // 将匹配到的字母转为大写,并替换掉前面的下划线
         matcher.appendReplacement(result, matcher.group(1).toUpperCase());
      }
      matcher.appendTail(result);
      return result.toString();
   }
   public static void main(String[] args) throws ParseException {
      /*List<String> dateList =getDateListBetweenDates(ActionUtil.sdf.parse("2025-01-01 00:00:00"),new Date());
      for (String date : dateList) {
         System.out.println(date);
      }*/
      //System.out.println(toCamelCase("user_name_and_age"));
      Date time1=getDateAdd(new Date(),-10);
      System.out.println(ActionUtil.sdf.format(time1));
   }
}