whyclxw
2 天以前 f998f917f90d86499bf8a24c8912e270655e4d43
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
package com.whyc.util;
 
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonSyntaxException;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
import org.apache.commons.io.FilenameUtils;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.*;
import java.lang.reflect.Type;
import java.text.ParseException;
import java.text.SimpleDateFormat;
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;
 
public class ActionUtil {
 
    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");
    public static SimpleDateFormat sdfwithday = new SimpleDateFormat("yyyy-MM-dd");
    public static SimpleDateFormat sdfwithtime = new SimpleDateFormat("HH:mm:ss");
    public static SimpleDateFormat sdfwithtime_yyyyMMdd_HH_mm_ss = new SimpleDateFormat(time_yyyyMMdd_HH_mm_ss);
    public static Object objeNull = null;
 
    /*
     * 获取HttpServletRequest
     */
    public static HttpServletRequest getRequest() {
        ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = requestAttributes.getRequest();
        return request;
    }
 
    /*
     * 获取HttpServletResponse
     */
    public static HttpServletResponse getResponse(){
        ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletResponse response = requestAttributes.getResponse();
        return response;
    }
    
    /*
     * 获取HttpSession
     */
    public static HttpSession getSession(){
        return getRequest().getSession();
    } 
    
    /**
     * 
     * @return    返回application
     */
    public static ServletContext getApplication(){
        return getSession().getServletContext();
    }
    //获取application中互斥上传的标志位flag
    public static int getFlag(){
        ServletContext app=getApplication();
        int flag=(Integer) app.getAttribute("flag");
        return flag;
    }
    ////给application中互斥上传的标志位flag设置值
    public static void setFlag(int flag){
        ServletContext app=getApplication();
        app.setAttribute("flag", flag);
    }
    /*
     * 获取将对象转换成json格式
     */
    public static String tojson(Object obj){
        Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create();
        return gson.toJson(obj);
    }
    
    public static String chageDateToString(Date time,String type){
        String msg = "";
        SimpleDateFormat sdf = new SimpleDateFormat(type);
        msg = sdf.format(time);
        return msg;
    }
    
    
    /**
     * 
     * @param datetype    需要解析的日期的格式如:"yyyy-MM-dd HH:mm:ss"
     * @return    得到对应的gson对象
     */
    public static Gson getGson(String datetype){
        return new  GsonBuilder().setDateFormat(datetype).create();
    }
    
    /**
     * 获取默认的gson对象
     * @return
     */
    public static Gson getGson(){
        return new Gson();
    }
    
    
    public static <T> T getObject(String jsonstring,Type listtype){
        Gson gson=new Gson();
        T t=null;
        try {
            t=gson.fromJson(jsonstring, listtype);
        } catch (JsonSyntaxException e) {
            e.printStackTrace();
        }
        return t;
    }
     
    /**
     * 
     * @return 获取输出流
     */
    public static PrintWriter getOut(){
        PrintWriter out =null;
        try {
            out=getResponse().getWriter();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return out;
    }
    
    /**
     * 
     * @param time    java.util包中的时间
     * @return        java.sql时间
     */
    public static Date getSimpDate(Date time){
        //System.out.println(time);
        return new java.sql.Date(time.getTime());
    }
    
    //使用MD5加密
    public static Object EncryptionMD5(Object obj){
        String md5=null;
        if(obj!=null && obj.toString().length()>0){
            md5= DigestUtils.md5Hex(obj.toString());
        }
        return md5;
    }
    
    //使用Base64加密
    public static Object EncryptionBase64(Object obj){
        String base64=null;
        if(obj!=null && obj.toString().length()>0){
            base64=new BASE64Encoder().encode(obj.toString().getBytes());
            base64 = base64.replaceAll("[\\s*\t\n\r]", "");         //替换加密后不换行
        }
        return base64;
    }
    
    //使用Base64解密
    public static Object DecryptionBase64(Object obj){
        String base64=null;
        if(obj!=null && obj.toString().length()>0){
            try {
                base64 = new String(new BASE64Decoder().decodeBuffer(obj.toString()));
            } catch (IOException e) {                
                e.printStackTrace();
            }
        }
        return base64;
    }
    
    //获取指定年月的天数
    public static int getDaysByYearMonth(int year, int month) {  
        
        Calendar a = Calendar.getInstance();  
        a.set(Calendar.YEAR, year);  
        a.set(Calendar.MONTH, month - 1);  
        a.set(Calendar.DATE, 1);  
        a.roll(Calendar.DATE, -1);  
        int maxDate = a.get(Calendar.DATE);  
        return maxDate;  
    }
 
    /**
     * 
     * @return 获取当前session 中的用户对象
     */
    public static User getUser(){
        HttpSession session =getSession();
        Object obj=session.getAttribute("user");
        User userInf = new User();
        if(obj==null){
            userInf.setName("hw");
            userInf.setId(1005);
        }else{
            userInf=(User) session.getAttribute("user");
        }
        return userInf;
    }
    
    //获取某年某月的起始和结束时间
    //需要注意的是:月份是从0开始的,比如说如果输入5的话,实际上显示的是4月份的最后一天,千万不要搞错了哦  
    public static String getLastDayOfMonth(int year, int month) {     
        Calendar cal = Calendar.getInstance();     
        cal.set(Calendar.YEAR, year);     
        cal.set(Calendar.MONTH, month);     
        cal.set(Calendar.DAY_OF_MONTH,cal.getActualMaximum(Calendar.DATE));  
       return  new   SimpleDateFormat( "yyyy-MM-dd ").format(cal.getTime())+"23:59:59";  
    } 
    
    public static String getFirstDayOfMonth(int year, int month) {     
        Calendar cal = Calendar.getInstance();     
        cal.set(Calendar.YEAR, year);     
        cal.set(Calendar.MONTH, month);  
        cal.set(Calendar.DAY_OF_MONTH,cal.getMinimum(Calendar.DATE));  
       return   new   SimpleDateFormat( "yyyy-MM-dd ").format(cal.getTime())+"00:00:00";  
    }  
    //获取当前时间的年份
    public static int getNowYear(){
        Calendar ca = Calendar.getInstance();//得到一个Calendar的实例 
        ca.setTime(new Date()); //设置时间为当前时间 
        int year = ca.get(Calendar.YEAR);
        //System.out.println(month);
        return year;
    }
    //获取当前时间的月份
    public static int getNowMonth(){
        Calendar ca = Calendar.getInstance();//得到一个Calendar的实例 
        ca.setTime(new Date()); //设置时间为当前时间 
        int month = ca.get(Calendar.MONTH) + 1;
        //System.out.println(month);
        return month;
    }
    //获取当前时间的日期
    public static int getNowday(){
        Calendar ca = Calendar.getInstance();//得到一个Calendar的实例 
        ca.setTime(new Date()); //设置时间为当前时间 
        int day = ca.get(Calendar.DAY_OF_MONTH);
        //System.out.println(month);
        return day;
    }
   //当前时间加上x小时
    public static String getDateAdd(int minute){
    Date date = new Date();
    Calendar c = Calendar.getInstance();
    c.setTime(date);
    c.add(Calendar.MINUTE, minute);
    return new   SimpleDateFormat( "yyyy-MM-dd HH:mm:ss").format(c.getTime());
    }
 
    /**
     * 输入验证:路径遍历,防止恶意符号影响文件体系
     * 过滤掉特殊字符 ”/\" : | * ? < >”
     */
    public static String filterFileName(String fileName){
        Pattern pattern = Pattern.compile("[\\s\\\\/:\\*\\?\\\"<>\\|]");
        Matcher matcher = pattern.matcher(fileName);
        fileName = matcher.replaceAll("");
        return FilenameUtils.getName(fileName);
    }
 
 
    //获取时间的年份
    public static int getDateYear(Date date){
        Calendar ca = Calendar.getInstance();//得到一个Calendar的实例 
        ca.setTime(date); //设置时间为当前时间 
        int year = ca.get(Calendar.YEAR);
        //System.out.println(month);
        return year;
    }
    //获取时间的月份
    public static int getDateMonth(Date date){
        Calendar ca = Calendar.getInstance();//得到一个Calendar的实例 
        ca.setTime(date); //设置时间为当前时间 
        int month = ca.get(Calendar.MONTH) + 1;
        //System.out.println(month);
        return month;
    }
    //获取时间的日期
    public static int getDateday(Date date){
        Calendar ca = Calendar.getInstance();//得到一个Calendar的实例 
        ca.setTime(date); //设置时间为当前时间 
        int day = ca.get(Calendar.DAY_OF_MONTH);
        //System.out.println(month);
        return day;
    }
    //当前时间加上x小时
    public static Date getDateAdd(Date date,int minute){
    Calendar c = Calendar.getInstance();
    c.setTime(date);
    c.add(Calendar.MINUTE, minute);
    return c.getTime();
    }
    //给定时间判断与当前时间相比是否为老电池(numYear为时间期限几年)
    public static int judgeBatt(Date inUseDate,Date date,int numYear){
        int judge=0;
        inUseDate.setYear(ActionUtil.getDateYear(inUseDate)+numYear-1900);
        //System.out.println("inUseDate: "+inUseDate);
        if(inUseDate.after(date)){
            judge=1;
        }else{
            judge=0;
        }
        return judge;
    }
    //获取某年某月某日内的时间<date为执行时间的时分秒设置为提醒时间段的时分秒>
    public static Date getWorkDay(Date date,Date noticeTime) {     
        Calendar cal = Calendar.getInstance();
        cal.setTime(date); //设置时间为执行日期
        int year = cal.get(Calendar.YEAR);//年
        int month = cal.get(Calendar.MONTH);//月
        int day = cal.get(Calendar.DAY_OF_MONTH);//日
        cal.setTime(noticeTime);//设置时间为提醒时间段
        /*int hour=cal.get(Calendar.HOUR_OF_DAY);//时
        int minute=cal.get(Calendar.MINUTE);//分
        int second=cal.get(Calendar.SECOND);//秒*/   
        cal.set(Calendar.YEAR, year);     
        cal.set(Calendar.MONTH, month);  
        cal.set(Calendar.DAY_OF_MONTH,day); 
        return  cal.getTime();
       } 
    //获取某年某月某日起始时间/结束时间
    public static String getDayTime(int year, int month,int day,int type) {     
        Calendar cal = Calendar.getInstance();     
        cal.set(Calendar.YEAR, year);     
        cal.set(Calendar.MONTH, month);
        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){
            return   new   SimpleDateFormat( "yyyy-MM-dd ").format(cal.getTime())+"17:00:00";  
        }else if(type==4){
            return   new   SimpleDateFormat( "yyyy-MM-dd ").format(cal.getTime())+"23:59:59";  
        }
       return   new   SimpleDateFormat( "yyyy-MM-dd ").format(cal.getTime());  
    } 
 
    //计算电池使用了多少个月
    public static int battInuseMonth(Date inUseDate){
        int useDay=0;
        Date nowd=new Date();//当前时间
        int inuseY=ActionUtil.getDateYear(inUseDate);
        int inuseM=ActionUtil.getDateMonth(inUseDate);
        int nowY=ActionUtil.getDateYear(nowd);
        int nowM=ActionUtil.getDateMonth(nowd);
        if(inuseY==nowY){
            useDay=nowM-inuseM;
        }else{
            useDay=(nowY-inuseY)*12+nowM-inuseM;
        }
        return useDay;
        
    }
    //计算日期之间相差的天数 
    public static int daysBetween(Date smdate,Date bdate)    
    {    
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");  
        
        try {
            smdate=sdf.parse(sdf.format(smdate));  
            bdate=sdf.parse(sdf.format(bdate));
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
      
        Calendar cal = Calendar.getInstance();    
        cal.setTime(smdate);    
        long time1 = cal.getTimeInMillis();                 
        cal.setTime(bdate);    
        long time2 = cal.getTimeInMillis();         
        long between_days=(time2-time1)/(1000*3600*24);  
            
       return Math.abs(Integer.parseInt(String.valueOf(between_days)));           
    }
    //计算日期之间相差的小时 
    public static int HoursBetween(Date smdate,Date bdate)    
    {    
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  
        try {
            smdate=sdf.parse(sdf.format(smdate));  
            bdate=sdf.parse(sdf.format(bdate));
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }  
        Calendar cal = Calendar.getInstance();    
        cal.setTime(smdate);    
        long time1 = cal.getTimeInMillis();                 
        cal.setTime(bdate);    
        long time2 = cal.getTimeInMillis();         
        long between_hours=(time2-time1)/(1000*3600);  
        //System.out.println("between_hours:"+between_hours);
        return (int) Math.abs(between_hours);           
    } 
    
    //比较两个时间的大小
    public static int compareDate(Date d1,Date d2){
        if (d1.getTime() > d2.getTime()) {
            return 1;
        } else if (d1.getTime() < d2.getTime()) {
            return -1;
        } 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: 
     * @return
     */
    public static String getImageStr(String imgFile) {
        InputStream inputStream = null;
        byte[] data = null;
        try {
            inputStream = new FileInputStream(imgFile);
            data = new byte[inputStream.available()];
            inputStream.read(data);
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if(inputStream!=null){
                try {
                    inputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        // 加密
        BASE64Encoder encoder = new BASE64Encoder();
        return encoder.encode(data);
    }
    
    
    /**
     * @Description: 将base64编码字符串转换为图片
     * @Author: 
     * @CreateTime: 
     * @param imgStr base64编码字符串
     * @param path 图片路径-具体到文件
     * @return
    */
    public static boolean generateImage(String imgStr, String path) {
        boolean bl=false;
        OutputStream out=null;
        if (imgStr == null) {
            bl=false;
        }
        BASE64Decoder decoder = new BASE64Decoder();
        try {
            // 解密
            byte[] b = decoder.decodeBuffer(imgStr);
            // 处理数据
            for (int i = 0; i < b.length; ++i) {
                if (b[i] < 0) {
                    b[i] += 256;
                }
            }
            out = new FileOutputStream(path);
            out.write(b);
            out.flush();
            bl=true;
        } catch (Exception e) {
            bl=false;
        }finally {
            if(out!=null){
                try {
                    out.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return bl;
    }
    
    /**
     * 将输入流中的数据读到字节数组中
     * @param is
     * @return
     */
    public static byte[] IStoByteArr(InputStream is){
        byte[] b = null;
        try {
            b = new byte[is.available()];
            is.read(b);
        } catch (IOException e) {
            e.printStackTrace();
        } finally{
            if(is != null){
                try {
                    is.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }                
            }
        }
        
        return b;
    }
 
    /**
     * 创建指定的文件文件,若不存在则先创建指定的文件夹再创建指定的文件
     * @param filePath
     */
    public static void createFilefolderIFNotExist(String filePath){
        File f = new File(filePath);
        if(!f.exists()){
            if(!f.getParentFile().exists()){
                f.getParentFile().mkdirs();
            }
        } 
    }
    /**
     * 秒转换小时-分-秒analytics/util/DateUtil.java
     *
     * @param seconds 秒为单位 比如..600秒
     * @return 比如...2小时3分钟52秒
     */
    public static String secToTime(int seconds) {
        int hour = seconds / 3600;
        int minute = (seconds - hour * 3600) / 60;
        int second = (seconds - hour * 3600 - minute * 60);
 
        StringBuffer sb = new StringBuffer();
        if (hour > 0) {
            if(hour<10){
                sb.append("0"+hour + ":");
            }else{
                sb.append(hour + ":");
            }
        }else{
            sb.append("00"+ ":");
        }
        if (minute > 0) {
            if(minute<10){
                sb.append("0"+minute + ":");
            }else{
                sb.append(minute + ":");
            }
        }else{
            sb.append("00" + ":");
        }
        if (second > 0) {
            if(second<10){
                sb.append("0"+second);
            }else{
                sb.append(second);
            }
        }else{
            sb.append("00");
        }
        return sb.toString();
    }
 
    /**
     * 使用timestamp+盐方式,进行签名验证
     * 当前时间戳为13位数
     */
    public static boolean checkSignMD5(String time,String randomStr,String sign){
        String usefulNum = randomStr;
        //加盐方式,根据末尾的值进行不同的加密规则
        char lastChar = time.charAt(12);
        int lastNum = Integer.parseInt(String.valueOf(lastChar));
        switch (lastNum){
            //在第一位加字符串 rd@c3doed
            case 0: usefulNum += time.replace(String.valueOf(lastChar),"rd@c3dozero");break;
            case 1: usefulNum += time.replace(String.valueOf(lastChar),"rd@c3doenoe");break;
            case 2: usefulNum += time.replace(String.valueOf(lastChar),"rd@c3doktwo");break;
            case 3: usefulNum += time.replace(String.valueOf(lastChar),"rd@c3dolthree");break;
            case 4: usefulNum += time.replace(String.valueOf(lastChar),"rd@c3doexfour");break;
            case 5: usefulNum += time.replace(String.valueOf(lastChar),"rd@c3doedefive");break;
            case 6: usefulNum += time.replace(String.valueOf(lastChar),"rd@c3doedhsix");break;
            case 7: usefulNum += time.replace(String.valueOf(lastChar),"rd@c3doedtseven");break;
            case 8: usefulNum += time.replace(String.valueOf(lastChar),"rd@c3doedbeight");break;
            case 9: usefulNum += time.replace(String.valueOf(lastChar),"rd@c3doedrnine");break;
        }
        //MD5加密后
        String signNow = (String) EncryptionMD5(usefulNum);
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < 10; i++) {
            sb.append(signNow.charAt(i * 2));
        }
        String signResult = sb.append(signNow).toString();
        return sign.equals(signResult);
    }
 
    //获取当前系统的语言环境
    public static String getLang() {
        Locale locale = Locale.getDefault();//对Locale类实例化定义
        String lang = locale.getLanguage();
        //String lang = "zh";
        String str = (String) ActionUtil.getSession().getAttribute("lang");
        if (str != null) {
            lang = str;
        }
        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));
    }
}