jinpengyong
2021-11-12 119473a723ff1f3acf077b14bccac4f16b418458
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
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
package com.moral.util;
 
 
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StringUtils;
 
import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.*;
 
@Slf4j
public class DateUtils {
    /**
     * 日期格式(yyyy)
     */
    public static final String yyyy = "yyyy";
    /**
     * 日期格式(yyyy-MM-dd)
     */
    public static final String yyyy_MM_dd_EN = "yyyy-MM-dd";
    /**
     * 日期格式(yyyy/MM/dd)
     */
    public static final String yyyy_MM_dd_decline = "yyyy/MM/dd";
    /**
     * 日期格式(yyyyMMdd)
     */
    public static final String yyyyMMdd_EN = "yyyyMMdd";
    /**
     * 日期格式(yyyy-MM)
     */
    public static final String yyyy_MM_EN = "yyyy-MM";
    /**
     * 日期格式(yyyyMM)
     */
    public static final String yyyyMM_EN = "yyyyMM";
    /**
     * 日期格式(yyyy-MM-dd HH:mm:ss)
     */
    public static final String yyyy_MM_dd_HH_mm_ss_EN = "yyyy-MM-dd HH:mm:ss";
    /**
     * 日期格式(yyyy-MM-dd HH:mm:ss.S)
     */
    public static final String yyyy_MM_dd_HH_mm_ss_S_EN = "yyyy-MM-dd HH:mm:ss.S";
    /**
     * 日期格式(yyyyMMddHHmmss)
     */
    public static final String yyyyMMddHHmmss_EN = "yyyyMMddHHmmss";
    /**
     * 日期格式(yyyy年MM月dd日)
     */
    public static final String yyyy_MM_dd_CN = "yyyy年MM月dd日";
    /**
     * 日期格式(yyyy年MM月dd日HH时mm分ss秒)
     */
    public static final String yyyy_MM_dd_HH_mm_ss_CN = "yyyy年MM月dd日HH时mm分ss秒";
    /**
     * 日期格式(yyyy年MM月dd日HH时mm分)
     */
    public static final String yyyy_MM_dd_HH_mm_CN = "yyyy年MM月dd日HH时mm分";
    /**
     * 北京boss订购接口报文头日期格式
     */
    public static final String BJBOSS_DATE = "yyyy-MM-dd'T'HH:mm:ss'Z'";
    /**
     * 日期格式(HH:mm:ss)
     */
    public static final String HH_mm_ss_EN = "HH:mm:ss";
    /*
     * 日期格式(yyyy-MM-dd HH:mm)
     * */
    public static final String yyyy_MM_dd_HH_mm_EN = "yyyy-MM-dd HH:mm";
    /*
     * 日期格式(yyyy-MM-dd HH)
     * */
    public static final String yyyy_MM_dd_HH_EN = "yyyy-MM-dd HH";
 
    /*
     * Date类toString格式
     * */
    public static final String EEE_MMM_dd_HH_mm_ss_zzz_yyyy = "EEE MMM dd HH:mm:ss zzz yyyy";
    /**
     * DateFormat缓存
     */
    private static Map<String, DateFormat> dateFormatMap = new HashMap<String, DateFormat>();
 
 
    /**
     * @Description: 获取指定小时的开始时间
     * @Param: [date]
     * @return: java.util.Date
     * @Author: 陈凯裕
     * @Date: 2021/9/26
     */
    public static Date getHourlyStartTime(Date date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        return cal.getTime();
    }
 
    /**
     * @Description: 获取指定小时的结束时间
     * @Param: [date]
     * @return: java.util.Date
     * @Author: 陈凯裕
     * @Date: 2021/9/26
     */
    public static Date getHourlyEndTime(Date date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.set(Calendar.MINUTE, 59);
        cal.set(Calendar.SECOND, 59);
        cal.set(Calendar.MILLISECOND, 0);
        return cal.getTime();
    }
 
    /**
     * @Description: 获取指定日期的第一个小时
     * @Param: [date]
     * @return: java.util.List<java.util.Date>
     * @Author: 陈凯裕
     * @Date: 2021/9/8
     */
    public static Date getDailyStartTime(Date date) {
        String dateStr = dateToDateString(date, "yyyy-MM-dd");
        String startDateStr = dateStr + " 00:00:00";
        Date startDate = getDate(startDateStr, "yyyy-MM-dd HH:mm:ss");
        return startDate;
    }
 
    /**
     * @Description: 获取指定日期的最后一个小时
     * @Param: [date]
     * @return: java.util.Date
     * @Author: 陈凯裕
     * @Date: 2021/9/26
     */
    public static Date getDailyEndTime(Date date) {
        String dateStr = dateToDateString(date, "yyyy-MM-dd");
        String endDateStr = dateStr + " 23:59:59";
        Date endDate = getDate(endDateStr, "yyyy-MM-dd HH:mm:ss");
        return endDate;
    }
 
 
    /**
     * @Description: 获取指定日期那周的第一天第一个小时
     * @Param: [date]
     * @return: java.util.Date
     * @Author: 陈凯裕
     * @Date: 2021/9/26
     */
    public static Date getWeeklyStartTime(Date date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        if (1 == cal.get(Calendar.DAY_OF_WEEK)) {
            cal.add(Calendar.DAY_OF_MONTH, -1);
        }
        cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        return cal.getTime();
    }
 
    /**
     * @Description: 获取指定日期那周的最后一天最后一个小时
     * @Param: [date]
     * @return: java.util.Date
     * @Author: 陈凯裕
     * @Date: 2021/9/26
     */
    public static Date getWeeklyEndTime(Date date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        if (1 != cal.get(Calendar.DAY_OF_WEEK)) {
            cal.add(Calendar.DAY_OF_MONTH, 7);
        }
        cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
        cal.set(Calendar.HOUR_OF_DAY, 23);
        cal.set(Calendar.MINUTE, 59);
        cal.set(Calendar.SECOND, 59);
        cal.set(Calendar.MILLISECOND, 0);
        return cal.getTime();
    }
 
    /**
     * @Description: 获取指定日期当月的第一天第一个小时
     * @Param: [date]
     * @return: java.util.Date
     * @Author: 陈凯裕
     * @Date: 2021/9/26
     */
    public static Date getMonthlyStartTime(Date date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.set(Calendar.DAY_OF_MONTH, cal.getActualMinimum(Calendar.DAY_OF_MONTH));
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        return cal.getTime();
    }
 
    /**
     * @Description: 获取指定日期当月的最后一天最后一个小时
     * @Param: [date]
     * @return: java.util.Date
     * @Author: 陈凯裕
     * @Date: 2021/9/26
     */
    public static Date getMonthlyEndTime(Date date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
        cal.set(Calendar.HOUR_OF_DAY, 23);
        cal.set(Calendar.MINUTE, 59);
        cal.set(Calendar.SECOND, 59);
        cal.set(Calendar.MILLISECOND, 0);
        return cal.getTime();
    }
 
 
    /**
     * @Description: Date的toString格式转为Date
     * @Param: []
     * @return: java.util.Date
     * @Author: 陈凯裕
     * @Date: 2021/8/25
     */
    public static Date dateStringToDate(String formatStr) {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat(EEE_MMM_dd_HH_mm_ss_zzz_yyyy, Locale.US);
            return sdf.parse(formatStr);
        } catch (ParseException e) {
            log.error(e.getMessage());
            return null;
        }
    }
 
    /**
     * 获取DateFormat
     *
     * @param formatStr
     * @return
     */
    public static DateFormat getDateFormat(String formatStr) {
        DateFormat df = dateFormatMap.get(formatStr);
        if (df == null) {
            df = new SimpleDateFormat(formatStr);
            dateFormatMap.put(formatStr, df);
        }
        return df;
    }
 
    public static Date getDate() {
        return Calendar.getInstance().getTime();
    }
 
    /**
     * 按照默认formatStr的格式,转化dateTimeStr为Date类型 dateTimeStr必须是formatStr的形式
     *
     * @param dateTimeStr
     * @param formatStr
     * @return
     */
    public static Date getDate(String dateTimeStr, String formatStr) {
        try {
            if (dateTimeStr == null || dateTimeStr.equals("")) {
                return null;
            }
            DateFormat sdf = getDateFormat(formatStr);
            return sdf.parse(dateTimeStr);
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
    }
 
    /**
     * 转化dateTimeStr为Date类型
     *
     * @param dateTimeStr
     * @return
     */
    public static Date convertDate(String dateTimeStr) {
        try {
            if (dateTimeStr == null || dateTimeStr.equals("")) {
                return null;
            }
            DateFormat sdf = getDateFormat(yyyy_MM_dd_EN);
            Date d = sdf.parse(dateTimeStr);
            return d;
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
    }
 
    /**
     * 按照默认显示日期时间的格式"yyyy-MM-dd",转化dateTimeStr为Date类型 dateTimeStr必须是"yyyy-MM-dd"的形式
     *
     * @param dateTimeStr
     * @return
     */
    public static Date getDate(String dateTimeStr) {
        return getDate(dateTimeStr, yyyy_MM_dd_EN);
    }
 
    /**
     * 将YYYYMMDD转换成Date日期
     *
     * @param date
     * @return
     * @throws Exception
     */
    public static Date transferDate(String date) throws Exception {
        if (date == null || date.length() < 1)
            return null;
 
        if (date.length() != 8)
            throw new Exception("日期格式错误");
        String con = "-";
 
        String yyyy = date.substring(0, 4);
        String mm = date.substring(4, 6);
        String dd = date.substring(6, 8);
 
        int month = Integer.parseInt(mm);
        int day = Integer.parseInt(dd);
        if (month < 1 || month > 12 || day < 1 || day > 31)
            throw new Exception("日期格式错误");
 
        String str = yyyy + con + mm + con + dd;
        return getDate(str, yyyy_MM_dd_EN);
    }
 
    /**
     * 将Date转换成字符串“yyyy-mm-dd hh:mm:ss”的字符串
     *
     * @param date
     * @return
     */
    public static String dateToDateString(Date date) {
        return dateToDateString(date, yyyy_MM_dd_HH_mm_ss_EN);
    }
 
    /**
     * 将Date转换成字符串“yyyymmddhhmmss”的字符串
     *
     * @param date
     * @return
     */
    public static String dateToDateFullString(Date date) {
        if (null == date)
            return null;
        else
            return dateToDateString(date, yyyyMMddHHmmss_EN);
    }
 
    /**
     * 将Date转换成formatStr格式的字符串
     *
     * @param date
     * @param formatStr
     * @return
     */
    public static String dateToDateString(Date date, String formatStr) {
        DateFormat df = getDateFormat(formatStr);
        return df.format(date);
    }
 
    /**
     * 将String转换成formatStr格式的字符串
     *
     * @param date
     * @param formatStr1
     * @param formatStr2
     * @return
     */
    public static String stringToDateString(String date, String formatStr1, String formatStr2) {
        Date d = getDate(date, formatStr1);
        DateFormat df = getDateFormat(formatStr2);
        return df.format(d);
    }
 
    /**
     * 获取当前日期yyyy-MM-dd的形式
     *
     * @return
     */
    public static String getCurDate() {
        return dateToDateString(new Date(), yyyy_MM_dd_EN);
    }
 
    /**
     * 获取当前日期
     *
     * @return
     */
    public static String getCurDate(String formatStr) {
        return dateToDateString(new Date(), formatStr);
    }
 
    /**
     * 获取当前日期yyyy年MM月dd日的形式
     *
     * @return
     */
    public static String getCurCNDate() {
        return dateToDateString(new Date(), yyyy_MM_dd_CN);
    }
 
    /**
     * 获取当前日期时间yyyy-MM-dd HH:mm:ss的形式
     *
     * @return
     */
    public static String getCurDateTime() {
        return dateToDateString(new Date(), yyyy_MM_dd_HH_mm_ss_EN);
    }
 
    /**
     * 获取当前日期时间yyyy年MM月dd日HH时mm分ss秒的形式
     *
     * @return
     */
    public static String getCurZhCNDateTime() {
        return dateToDateString(new Date(), yyyy_MM_dd_HH_mm_ss_CN);
    }
 
    /**
     * 比较两个"yyyy-MM-dd HH:mm:ss"格式的日期,之间相差多少毫秒,time2-time1
     *
     * @param time1
     * @param time2
     * @return
     */
    public static long compareDateStr(String time1, String time2) {
        Date d1 = getDate(time1);
        Date d2 = getDate(time2);
        return d2.getTime() - d1.getTime();
    }
 
    /**
     * 比较任意格式时间相差毫秒数
     *
     * @param time1
     * @param time2
     * @param format
     * @return
     */
    public static long compareDateStr(String time1, String time2, String format) {
        Date d1 = getDate(time1, format);
        Date d2 = getDate(time2, format);
        return d2.getTime() - d1.getTime();
    }
 
    /**
     * 比较起始时间与当前时间相差毫秒数
     *
     * @param time
     * @param format
     * @return
     */
    public static long compareDateNow(String time, String format) {
        Date date = getDate(time, format);
        return new Date().getTime() - date.getTime();
    }
 
    /**
     * 比较两个"yyyy-MM-dd HH:mm:ss"格式的日期,之间相差多少毫秒,time2-time1
     *
     * @param time1
     * @param time2
     * @return
     */
    public static long compareDateStr(Date time1, Date time2) {
        return time2.getTime() - time1.getTime();
    }
 
    /**
     * nows时间大于date时间 为true
     *
     * @param nows
     * @param date
     * @return
     */
    public static boolean isTimeBefor(Date nows, Date date) {
        long hous = nows.getTime() - date.getTime();
        if (hous > 0) {
            return true;
        } else {
            return false;
        }
    }
 
    /**
     * 将小时数换算成返回以毫秒为单位的时间
     *
     * @param hours
     * @return
     */
    public static long getMicroSec(BigDecimal hours) {
        BigDecimal bd;
        bd = hours.multiply(new BigDecimal(3600 * 1000));
        return bd.longValue();
    }
 
    /**
     * 获取当前日期years年后的一个(formatStr)的字符串
     *
     * @param years
     * @param formatStr
     * @return
     */
    public static String getDateStringOfYear(int years, String formatStr) {
        Calendar now = Calendar.getInstance(TimeZone.getDefault());
        now.setTime(new Date());
        now.add(Calendar.YEAR, years);
        return dateToDateString(now.getTime(), formatStr);
    }
 
    /**
     * 获取当前日期mon月后的一个(formatStr)的字符串
     *
     * @param months
     * @param formatStr
     * @return
     */
    public static String getDateStringOfMon(int months, String formatStr) {
        Calendar now = Calendar.getInstance(TimeZone.getDefault());
        now.setTime(new Date());
        now.add(Calendar.MONTH, months);
        return dateToDateString(now.getTime(), formatStr);
    }
 
    /**
     * 获取当前日期days天后的一个(formatStr)的字符串
     *
     * @param days
     * @param formatStr
     * @return
     */
    public static String getDateStringOfDay(int days, String formatStr) {
        Calendar now = Calendar.getInstance(TimeZone.getDefault());
        now.setTime(new Date());
        now.add(Calendar.DATE, days);
        return dateToDateString(now.getTime(), formatStr);
    }
 
    /**
     * 判断日期是否是今天
     *
     * @param date
     * @return
     */
    public static int theDateIsToday(String date, String format) {
        String theDate = stringToDateString(date, format, yyyyMMdd_EN);
        String today = getDateStringOfDay(0, yyyyMMdd_EN);
        if (theDate.equals(today)) {
            return 1;
        } else {
            return 0;
        }
    }
 
    /**
     * 获取当前日期hours小时后的一个(formatStr)的字符串
     *
     * @param hours
     * @param formatStr
     * @return
     */
    public static String getDateStringOfHour(int hours, String formatStr) {
        Calendar now = Calendar.getInstance(TimeZone.getDefault());
        now.setTime(new Date());
        now.add(Calendar.HOUR_OF_DAY, hours);
        return dateToDateString(now.getTime(), formatStr);
    }
 
    /**
     * 获取指定日期mon月后的一个(formatStr)的字符串
     *
     * @param date
     * @param mon
     * @param formatStr
     * @return
     */
    public static String getDateOfMon(String date, int mon, String formatStr) {
        Calendar now = Calendar.getInstance(TimeZone.getDefault());
        now.setTime(getDate(date, formatStr));
        now.add(Calendar.MONTH, mon);
        return dateToDateString(now.getTime(), formatStr);
    }
 
 
    /**
     * 获取指定日期day天后的一个(formatStr)的字符串
     *
     * @param date
     * @param day
     * @param formatStr
     * @return
     */
    public static String getDateOfDay(String date, int day, String formatStr) {
        Calendar now = Calendar.getInstance(TimeZone.getDefault());
        now.setTime(getDate(date, formatStr));
        now.add(Calendar.DATE, day);
        return dateToDateString(now.getTime(), formatStr);
    }
 
    /**
     * @Description: 获取指定日期day天后的日期
     * @Param: [date, day]
     * @return: java.util.Date
     * @Author: 陈凯裕
     * @Date: 2021/3/30
     */
    public static Date getDateOfDay(Date date, int day) {
        if (date == null)
            return null;
        Calendar now = Calendar.getInstance(TimeZone.getDefault());
        now.setTime(date);
        now.add(Calendar.DAY_OF_MONTH, day);
        return now.getTime();
    }
 
 
    public static Date getDate(Date beginDate, int ds) {
        if (ds == 0)
            return new Date();
        try {
            SimpleDateFormat dft = new SimpleDateFormat("yyyy-MM-dd");
            Calendar date = Calendar.getInstance();
            date.setTime(beginDate);
            date.set(Calendar.DATE, date.get(Calendar.DATE) - ds);
            Date endDate = dft.parse(dft.format(date.getTime()));
            return endDate;
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return new Date();
    }
 
    public static String getAfterNDays(Date date, int n, String formateStr) {
        SimpleDateFormat sdf = new SimpleDateFormat(formateStr);
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(date);
        calendar.add(Calendar.DATE, n);
        return sdf.format(calendar.getTime());
    }
 
    /**
     * 获取指定日期mins分钟后的一个(formatStr)的字符串
     *
     * @param date
     * @param mins
     * @param formatStr
     * @return
     */
    public static String getDateOfMin(String date, int mins, String formatStr) {
        Calendar now = Calendar.getInstance(TimeZone.getDefault());
        now.setTime(getDate(date, formatStr));
        now.add(Calendar.SECOND, mins * 60);
        return dateToDateString(now.getTime(), formatStr);
    }
 
    /**
     * 获取指定日期mins分钟后的一个日期
     *
     * @param date
     * @param mins
     * @return
     */
    public static Date getDateOfMin(Date date, int mins) {
        Calendar now = Calendar.getInstance(TimeZone.getDefault());
        now.setTime(date);
        now.add(Calendar.SECOND, mins * 60);
        return now.getTime();
    }
 
    /**
     * 获取当前日期mins分钟后的一个(formatStr)的字符串
     *
     * @param mins
     * @param formatStr
     * @return
     */
    public static String getDateStringOfMin(int mins, String formatStr) {
        Calendar now = Calendar.getInstance(TimeZone.getDefault());
        now.setTime(new Date());
        now.add(Calendar.MINUTE, mins);
        return dateToDateString(now.getTime(), formatStr);
    }
 
    /**
     * 获取当前日期mins分钟后的一个日期
     *
     * @param mins
     * @return
     */
    public static Date getDateOfMin(int mins) {
        Calendar now = Calendar.getInstance(TimeZone.getDefault());
        now.setTime(new Date());
        now.add(Calendar.MINUTE, mins);
        return now.getTime();
    }
 
    /**
     * 获取当前日期sec秒后的一个(formatStr)的字符串
     *
     * @param sec
     * @param formatStr
     * @return
     */
    public static String getDateStringOfSec(int sec, String formatStr) {
        Calendar now = Calendar.getInstance(TimeZone.getDefault());
        now.setTime(new Date());
        now.add(Calendar.SECOND, sec);
        return dateToDateString(now.getTime(), formatStr);
    }
 
    /**
     * 获得指定日期月份的天数
     *
     * @return
     */
    public static int getMonthDay(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        return c.getActualMaximum(Calendar.DAY_OF_MONTH);
 
    }
 
    /**
     * 获得系统当前月份的天数
     *
     * @return
     */
    public static int getCurentMonthDay() {
        Date date = Calendar.getInstance().getTime();
        return getMonthDay(date);
    }
 
    /**
     * 获得指定日期月份的天数 yyyy-mm-dd
     *
     * @return
     */
    public static int getMonthDay(String date) {
        Date strDate = getDate(date, yyyy_MM_dd_EN);
        return getMonthDay(strDate);
    }
 
    /**
     * 获取19xx,20xx形式的年
     *
     * @param d
     * @return
     */
    public static int getYear(Date d) {
        Calendar now = Calendar.getInstance(TimeZone.getDefault());
        now.setTime(d);
        return now.get(Calendar.YEAR);
    }
 
    /**
     * 获取月份,1-12月
     *
     * @param d
     * @return
     */
    public static int getMonth(Date d) {
        Calendar now = Calendar.getInstance(TimeZone.getDefault());
        now.setTime(d);
        return now.get(Calendar.MONTH) + 1;
    }
 
    /**
     * 获取xxxx-xx-xx的日
     *
     * @param d
     * @return
     */
    public static int getDay(Date d) {
        Calendar now = Calendar.getInstance(TimeZone.getDefault());
        now.setTime(d);
        return now.get(Calendar.DAY_OF_MONTH);
    }
 
    /**
     * 获取Date中的小时(24小时)
     *
     * @param d
     * @return
     */
    public static int getHour(Date d) {
        Calendar now = Calendar.getInstance(TimeZone.getDefault());
        now.setTime(d);
        return now.get(Calendar.HOUR_OF_DAY);
    }
 
    /**
     * 获取Date中的分钟
     *
     * @param d
     * @return
     */
    public static int getMin(Date d) {
        Calendar now = Calendar.getInstance(TimeZone.getDefault());
        now.setTime(d);
        return now.get(Calendar.MINUTE);
    }
 
    /**
     * 获取Date中的秒
     *
     * @param d
     * @return
     */
    public static int getSecond(Date d) {
        Calendar now = Calendar.getInstance(TimeZone.getDefault());
        now.setTime(d);
        return now.get(Calendar.SECOND);
    }
 
    /**
     * 得到本周周一
     *
     * @return yyyy-MM-dd
     */
    public static String getMondayOfThisWeek() {
        Calendar c = Calendar.getInstance();
        int day_of_week = c.get(Calendar.DAY_OF_WEEK) - 1;
        if (day_of_week == 0)
            day_of_week = 7;
        c.add(Calendar.DATE, -day_of_week + 1);
        return dateToDateString(c.getTime(), yyyy_MM_dd_EN);
    }
 
    /**
     * 得到本周周日
     *
     * @return yyyy-MM-dd
     */
    public static String getSundayOfThisWeek() {
        Calendar c = Calendar.getInstance();
        int day_of_week = c.get(Calendar.DAY_OF_WEEK) - 1;
        if (day_of_week == 0)
            day_of_week = 7;
        c.add(Calendar.DATE, -day_of_week + 7);
        return dateToDateString(c.getTime());
    }
 
    /**
     * 得到本周周(*)
     *
     * @return yyyy-MM-dd
     */
    public static String getDayOfThisWeek(int num) {
        Calendar c = Calendar.getInstance();
        int day_of_week = c.get(Calendar.DAY_OF_WEEK) - 1;
        if (day_of_week == 0)
            day_of_week = 7;
        c.add(Calendar.DATE, -day_of_week + num);
        return dateToDateString(c.getTime(), yyyy_MM_dd_EN);
    }
 
    /**
     * 得到本月指定天
     *
     * @return yyyy-MM-dd
     */
    public static String getDayOfThisMoon(String num) {
        String date = dateToDateString(new Date(), yyyy_MM_EN);
        date = date + "-" + num;
        return date;
    }
 
    /**
     * 获取两个日期相差的天数
     *
     * @param beginDate
     * @param endDate
     * @return
     */
    public static long getQuotByDays(String beginDate, String endDate) {
        long quot = 0;
        DateFormat df = getDateFormat(yyyy_MM_dd_EN);
        try {
            Date d1 = df.parse(beginDate);
            Date d2 = df.parse(endDate);
            quot = d2.getTime() - d1.getTime();
            quot = quot / 1000 / 60 / 60 / 24;
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
        return quot;
    }
 
    /**
     * 根据日期追加的天数,得到一个新日期
     *
     * @param date
     * @param days
     * @return
     */
    public static String getDateAddDay(String date, int days) {
        DateFormat df = getDateFormat(yyyy_MM_dd_EN);
        try {
            Calendar cal = Calendar.getInstance();
            cal.setTime(df.parse(date));
            cal.set(Calendar.DAY_OF_YEAR, cal.get(Calendar.DAY_OF_YEAR) + days);
 
            date = df.format(cal.getTime());
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
        return date;
    }
 
    /**
     * 获取当前月第一天
     *
     * @return
     */
    public static Date getFirstDayOfCurrMonth() {
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.DAY_OF_MONTH, 1);
        return getDate(dateToDateString(cal.getTime(), yyyy_MM_dd_EN));
    }
 
    /*
    * 获取今年的第一天
    * */
    public static Date getFirstDayOfCurrYear(){
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.DAY_OF_YEAR,1);
        return getDate(dateToDateString(cal.getTime(), yyyy_MM_dd_EN));
    }
 
    /**
     * 获取当前月的最后一天
     *
     * @return
     */
    public static Date getLastDayOfCurrMonth() {
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.MONTH, 1);
        cal.set(Calendar.DAY_OF_MONTH, 0);
        return getDate(dateToDateString(cal.getTime(), yyyy_MM_dd_EN));
    }
 
    /**
     * 根据日期追加的天数,得到一个新日期
     *
     * @param date
     * @param m
     * @return
     */
    public static String getDateAddMonth(String date, int m) {
        DateFormat df = getDateFormat(yyyy_MM_EN);
        try {
            Calendar cal = Calendar.getInstance();
            cal.setTime(df.parse(date));
            cal.add(Calendar.MONTH, m);
            date = df.format(cal.getTime());
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
        return date;
    }
 
    /**
     * 获取指定年月的第一天
     *
     * @param year
     * @param month
     * @return
     */
    public static String getFirstDayOfMonth(int year, int month) {
        Calendar cal = Calendar.getInstance();
        // 设置年份
        cal.set(Calendar.YEAR, year);
        // 设置月份
        cal.set(Calendar.MONTH, month - 1);
        // 获取某月最小天数
        int lastDay = cal.getActualMinimum(Calendar.DAY_OF_MONTH);
        // 设置日历中月份的最大天数
        cal.set(Calendar.DAY_OF_MONTH, lastDay);
        // 格式化日期
        DateFormat df = getDateFormat(yyyy_MM_dd_EN);
        return df.format(cal.getTime());
    }
 
    /**
     * 获取指定年月的第一天
     *
     * @param year
     * @param month
     * @return
     */
    public static String getLastDayOfMonth(int year, int month) {
        Calendar cal = Calendar.getInstance();
        // 设置年份
        cal.set(Calendar.YEAR, year);
        // 设置月份
        cal.set(Calendar.MONTH, month - 1);
        // 获取某月最大天数
        int lastDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
        // 设置日历中月份的最大天数
        cal.set(Calendar.DAY_OF_MONTH, lastDay);
        // 格式化日期
        DateFormat df = getDateFormat(yyyy_MM_dd_EN);
        return df.format(cal.getTime());
    }
 
    /**
     * 获取昨天日期
     *
     * @param date
     * @return
     * @throws ParseException
     */
    public static String getYesterday(Date date) throws ParseException {
        DateFormat df = getDateFormat(yyyy_MM_dd_EN);
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(df.parse(df.format(date)));
        calendar.add(Calendar.DAY_OF_MONTH, -1);
        return df.format(calendar.getTime());
    }
 
    /*
    * 获取昨天Date
    * */
    public static Date getYesterdayDate(){
        Calendar cal = Calendar.getInstance();
        cal.setTime(new Date());
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.add(Calendar.DAY_OF_MONTH, -1);
        return cal.getTime();
    }
 
    /**
     * 10位时间戳转时间
     *
     * @param dateInt
     * @param format
     * @return
     */
    public static String getIntToStr(String dateInt, String format) {
        DateFormat df = getDateFormat(format);
        long times = Integer.parseInt(dateInt) * 1000L;
        Date date = new Date(times);
        return df.format(date);
    }
 
    /**
     * 获取 10位时间戳
     *
     * @return
     */
    public static Integer getDateInt() {
        return (int) (System.currentTimeMillis() / 1000);
    }
 
    /**
     * 13位时间戳转时间
     *
     * @param time
     * @param format
     * @return
     */
    public static String getLongToStr(long time, String format) {
        Date date = new Date(time);
        return dateToDateString(date, format);
    }
 
    /**
     * 获取两个小时间的间隔秒杀
     *
     * @param start
     * @param end
     * @return
     */
    public static int getIntervalSec(int start, int end) {
        return (end - start) * 60 * 60;
    }
 
    /**
     * 毫秒时间戳毫秒加小数点
     *
     * @param time
     * @return
     */
    public static String getMillsStr(long time) {
        String timeStr = String.valueOf(time);
        String suffix = timeStr.substring(0, timeStr.length() - 3);
        String prefix = timeStr.substring(timeStr.length() - 3, timeStr.length());
        return suffix + "." + prefix;
    }
 
    /**
     * 带小数点的毫秒时间戳转时间格式
     *
     * @param timeStr
     * @param formatStr
     * @return
     */
    public static String longToString(String timeStr, String formatStr) {
        long times = Long.parseLong(timeStr.replace(".", ""));
        Date date = new Date(times);
        return dateToDateString(date, formatStr);
    }
 
    /**
     * 获取当天起始时间
     *
     * @return
     */
    public static Long getTodayTime() {
        Calendar todayStart = Calendar.getInstance();
        todayStart.set(Calendar.HOUR_OF_DAY, 0);
        todayStart.set(Calendar.MINUTE, 0);
        todayStart.set(Calendar.SECOND, 0);
        todayStart.set(Calendar.MILLISECOND, 0);
        return todayStart.getTime().getTime();
    }
 
 
    public static Integer getTodayInt() {
        return (int) (getTodayTime() / 1000);
    }
 
    /**
     * 获取当天结束时间
     *
     * @return
     */
    public static Long getEndTime() {
        Calendar todayEnd = Calendar.getInstance();
        todayEnd.set(Calendar.HOUR, 23);
        todayEnd.set(Calendar.MINUTE, 59);
        todayEnd.set(Calendar.SECOND, 59);
        todayEnd.set(Calendar.MILLISECOND, 999);
        return todayEnd.getTime().getTime();
    }
 
    public static Integer getTomorrowInt() {
        return (int) (getTomorrowTime() / 1000);
    }
 
    /**
     * 获取第二天起始时间
     *
     * @return
     */
    public static Long getTomorrowTime() {
        Calendar cal = Calendar.getInstance();
        cal.setTime(new Date());
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        cal.add(Calendar.DAY_OF_MONTH, 1);
        return cal.getTime().getTime();
    }
 
    /**
     * 获取当天指定小时的时间
     *
     * @param hour
     * @return
     */
    public static Long getPointHourTime(int hour) {
        Calendar todayStart = Calendar.getInstance();
        todayStart.set(Calendar.HOUR_OF_DAY, hour);
        todayStart.set(Calendar.MINUTE, 0);
        todayStart.set(Calendar.SECOND, 0);
        todayStart.set(Calendar.MILLISECOND, 0);
        return todayStart.getTime().getTime();
    }
 
    /**
     * 获取当天n天后的h小时
     *
     * @param days
     * @param hour
     * @return
     */
    public static Long getPointDateHourTime(int days, int hour) {
        Calendar todayStart = Calendar.getInstance();
        todayStart.add(Calendar.DATE, days);
        todayStart.set(Calendar.HOUR_OF_DAY, hour);
        todayStart.set(Calendar.MINUTE, 0);
        todayStart.set(Calendar.SECOND, 0);
        todayStart.set(Calendar.MILLISECOND, 0);
        return todayStart.getTime().getTime();
    }
 
    /**
     * 时分秒转成秒数
     *
     * @param time
     * @return
     */
    public static Integer hourTosec(String time) {
        if ("null".equals(time) || StringUtils.isEmpty(time)) {
            return null;
        }
        if (time.length() <= 5) {
            time += ":00";
        }
        int index1 = time.indexOf(":");
        int index2 = time.indexOf(":", index1 + 1);
        int hh = Integer.parseInt(time.substring(0, index1));
        int mi = Integer.parseInt(time.substring(index1 + 1, index2));
        int ss = Integer.parseInt(time.substring(index2 + 1));
        return hh * 60 * 60 + mi * 60 + ss;
    }
 
    /**
     * 时分秒转成秒数
     *
     * @param time
     * @return
     */
    public static Integer minTosec(String time) {
        if (time.length() <= 5) {
            time += ":00";
        }
        int index1 = time.indexOf(":");
        int index2 = time.indexOf(":", index1 + 1);
        int mi = Integer.parseInt(time.substring(0, index1));
        int ss = Integer.parseInt(time.substring(index1 + 1, index2));
        return mi * 60 + ss;
    }
 
 
    public static boolean isDate(String dateTimeStr, String formatStr) {
        DateFormat df = getDateFormat(formatStr);
        try {
            df.parse(dateTimeStr);
            return true;
        } catch (Exception e) {
            return false;
        }
    }
 
    /**
     * 判断时间是否在时间段内
     *
     * @param strDate      当前时间 yyyy-MM-dd HH:mm:ss
     * @param strDateBegin 开始时间 00:00:00
     * @param strDateEnd   结束时间 00:05:00
     * @return
     */
    public static boolean isInDate(String strDate, String strDateBegin, String strDateEnd) {
        // 截取当前时间时分秒
        int strDateH = Integer.parseInt(strDate.substring(11, 13));
        int strDateM = Integer.parseInt(strDate.substring(14, 16));
        int strDateS = Integer.parseInt(strDate.substring(17, 19));
        // 截取开始时间时分秒
        int strDateBeginH = Integer.parseInt(strDateBegin.substring(0, 2));
        int strDateBeginM = Integer.parseInt(strDateBegin.substring(3, 5));
        int strDateBeginS = Integer.parseInt(strDateBegin.substring(6, 8));
        // 截取结束时间时分秒
        int strDateEndH = Integer.parseInt(strDateEnd.substring(0, 2));
        int strDateEndM = Integer.parseInt(strDateEnd.substring(3, 5));
        int strDateEndS = Integer.parseInt(strDateEnd.substring(6, 8));
        if ((strDateH >= strDateBeginH && strDateH <= strDateEndH)) {
            // 当前时间小时数在开始时间和结束时间小时数之间
            if (strDateH > strDateBeginH && strDateH < strDateEndH) {
                return true;
                // 当前时间小时数等于开始时间小时数,分钟数在开始和结束之间
            } else if (strDateH == strDateBeginH && strDateM >= strDateBeginM && strDateM <= strDateEndM) {
                return true;
                // 当前时间小时数等于开始时间小时数,分钟数等于开始时间分钟数,秒数在开始和结束之间
            } else if (strDateH == strDateBeginH && strDateM == strDateBeginM && strDateS >= strDateBeginS
                    && strDateS <= strDateEndS) {
                return true;
            }
            // 当前时间小时数大等于开始时间小时数,等于结束时间小时数,分钟数小等于结束时间分钟数
            else if (strDateH >= strDateBeginH && strDateH == strDateEndH && strDateM <= strDateEndM) {
                return true;
                // 当前时间小时数大等于开始时间小时数,等于结束时间小时数,分钟数等于结束时间分钟数,秒数小等于结束时间秒数
            } else if (strDateH >= strDateBeginH && strDateH == strDateEndH && strDateM == strDateEndM
                    && strDateS <= strDateEndS) {
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
    }
 
    /**
     * 判断时间是否在时间段内
     *
     * @param date         当前时间 yyyy-MM-dd HH:mm:ss
     * @param strDateBegin 开始时间 00:00:00
     * @param strDateEnd   结束时间 00:05:00
     * @return
     */
    public static boolean isInDate(Date date, String strDateBegin, String strDateEnd) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String strDate = sdf.format(date);
        // 截取当前时间时分秒
        int strDateH = Integer.parseInt(strDate.substring(11, 13));
        int strDateM = Integer.parseInt(strDate.substring(14, 16));
        int strDateS = Integer.parseInt(strDate.substring(17, 19));
        // 截取开始时间时分秒
        int strDateBeginH = Integer.parseInt(strDateBegin.substring(0, 2));
        int strDateBeginM = Integer.parseInt(strDateBegin.substring(3, 5));
        int strDateBeginS = Integer.parseInt(strDateBegin.substring(6, 8));
        // 截取结束时间时分秒
        int strDateEndH = Integer.parseInt(strDateEnd.substring(0, 2));
        int strDateEndM = Integer.parseInt(strDateEnd.substring(3, 5));
        int strDateEndS = Integer.parseInt(strDateEnd.substring(6, 8));
        if ((strDateH >= strDateBeginH && strDateH <= strDateEndH)) {
            // 当前时间小时数在开始时间和结束时间小时数之间
            if (strDateH > strDateBeginH && strDateH < strDateEndH) {
                return true;
                // 当前时间小时数等于开始时间小时数,分钟数在开始和结束之间
            } else if (strDateH == strDateBeginH && strDateM >= strDateBeginM && strDateM <= strDateEndM) {
                return true;
                // 当前时间小时数等于开始时间小时数,分钟数等于开始时间分钟数,秒数在开始和结束之间
            } else if (strDateH == strDateBeginH && strDateM == strDateBeginM && strDateS >= strDateBeginS
                    && strDateS <= strDateEndS) {
                return true;
            }
            // 当前时间小时数大等于开始时间小时数,等于结束时间小时数,分钟数小等于结束时间分钟数
            else if (strDateH >= strDateBeginH && strDateH == strDateEndH && strDateM <= strDateEndM) {
                return true;
                // 当前时间小时数大等于开始时间小时数,等于结束时间小时数,分钟数等于结束时间分钟数,秒数小等于结束时间秒数
            } else if (strDateH >= strDateBeginH && strDateH == strDateEndH && strDateM == strDateEndM
                    && strDateS <= strDateEndS) {
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
    }
 
    public static boolean isInTime(int time, int begin, int end) {
        if (time >= begin && time < end) {
            return true;
        }
        return false;
    }
 
    public static int getMinutest(String begin, String format) {
        String nowMinutes = getCurDate("HH:mm");
        long time = compareDateStr("09:00", nowMinutes, "HH:mm");
        return (int) time;
    }
 
    /**
     * <p>
     * Title: addDays
     * </p>
     * <p>
     * Description: 加减天数
     * </p>
     *
     * @param days
     * @return
     */
    public static Date addDays(Date date, int days) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.DATE, days);
        return calendar.getTime();
    }
 
    /**
     * <p>
     * Title: addMonths
     * </p>
     * <p>
     * Description: 加减月份
     * </p>
     *
     * @param date
     * @param months
     * @return
     */
    public static Date addMonths(Date date, int months) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.MONTH, months);
        return calendar.getTime();
    }
 
    /**
     * <p>
     * Title: getDays
     * </p>
     * <p>
     * Description: 获取两个日期之前相差的天数
     * </p>
     *
     * @param minDate
     * @param maxDate
     * @return
     */
    public static int getDays(Date minDate, Date maxDate) {
        int days = 0;
        if (null == minDate || null == maxDate)
            return days;
        days = (int) ((maxDate.getTime() - minDate.getTime()) / (24 * 60 * 60 * 1000));
        return days;
    }
 
    /**
     * @Description: 获取两个日期相差几个月
     * @Param: [start, end]
     * @return: int
     * @Author: 陈凯裕
     * @Date: 2021/9/23
     */
    public static int getMonth(Date start, Date end) {
        if (start.after(end)) {
            Date t = start;
            start = end;
            end = t;
        }
        Calendar startCalendar = Calendar.getInstance();
        startCalendar.setTime(start);
        Calendar endCalendar = Calendar.getInstance();
        endCalendar.setTime(end);
        Calendar temp = Calendar.getInstance();
        temp.setTime(end);
        temp.add(Calendar.DATE, 1);
 
        int year = endCalendar.get(Calendar.YEAR)
                - startCalendar.get(Calendar.YEAR);
        int month = endCalendar.get(Calendar.MONTH)
                - startCalendar.get(Calendar.MONTH);
 
        if ((startCalendar.get(Calendar.DATE) == 1)
                && (temp.get(Calendar.DATE) == 1)) {
            return year * 12 + month + 1;
        } else if ((startCalendar.get(Calendar.DATE) != 1)
                && (temp.get(Calendar.DATE) == 1)) {
            return year * 12 + month;
        } else if ((startCalendar.get(Calendar.DATE) == 1)
                && (temp.get(Calendar.DATE) != 1)) {
            return year * 12 + month;
        } else {
            return (year * 12 + month - 1) < 0 ? 0 : (year * 12 + month);
        }
    }
 
    /**
     * @Description: 获取两个日期之间所有的月份
     * @Param: [start, end]
     * @return: java.util.List<java.lang.String>
     * @Author: 陈凯裕
     * @Date: 2021/9/23
     */
    public static List<String> getAllMonth(Date start, Date end) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(start);
        // 获取开始年份和开始月份
        int startYear = calendar.get(Calendar.YEAR);
        int startMonth = calendar.get(Calendar.MONTH);
        // 获取结束年份和结束月份
        calendar.setTime(end);
        int endYear = calendar.get(Calendar.YEAR);
        int endMonth = calendar.get(Calendar.MONTH);
        //
        List<String> list = new ArrayList<String>();
 
        for (int i = startYear; i <= endYear; i++) {
            String date = "";
            if (startYear == endYear) {
                for (int j = startMonth; j <= endMonth; j++) {
                    if (j < 9) {
                        date = i + "-0" + (j + 1);
                    } else {
                        date = i + "-" + (j + 1);
                    }
                    list.add(date);
                }
 
            } else {
                if (i == startYear) {
                    for (int j = startMonth; j < 12; j++) {
                        if (j < 9) {
                            date = i + "-0" + (j + 1);
                        } else {
                            date = i + "-" + (j + 1);
                        }
                        list.add(date);
                    }
                } else if (i == endYear) {
                    for (int j = 0; j <= endMonth; j++) {
                        if (j < 9) {
                            date = i + "-0" + (j + 1);
                        } else {
                            date = i + "-" + (j + 1);
                        }
                        list.add(date);
                    }
                } else {
                    for (int j = 0; j < 12; j++) {
                        if (j < 9) {
                            date = i + "-0" + (j + 1);
                        } else {
                            date = i + "-" + (j + 1);
                        }
                        list.add(date);
                    }
                }
 
            }
 
        }
 
        return list;
    }
 
    /**
     * @Description: 获取两个日期之间所有的年份
     * @Param: [start, end]
     * @return: java.util.List<java.lang.String>
     * @Author: 陈凯裕
     * @Date: 2021/9/23
     */
    public static List<String> getAllYear(Date start, Date end) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(start);
        int startYear = calendar.get(Calendar.YEAR);
        calendar.setTime(end);
        int endYear = calendar.get(Calendar.YEAR);
 
        List<String> list = new ArrayList<>();
        list.add(String.valueOf(startYear));
 
        int i = endYear - startYear;
 
        for (int j = 1; j < i + 1; j++) {
            list.add(String.valueOf(startYear + j));
        }
 
        return list;
    }
 
    public static List<String> getAllDays(Date start, Date end) {
        List<String> list = new ArrayList<String>();
        SimpleDateFormat outformat = new SimpleDateFormat("yyyy-MM-dd");
 
        Calendar sCalendar = Calendar.getInstance();
        sCalendar.setTime(start);
        int year = sCalendar.get(Calendar.YEAR);
        int month = sCalendar.get(Calendar.MONTH);
        int day = sCalendar.get(Calendar.DATE);
        sCalendar.set(year, month, day, 0, 0, 0);
 
        Calendar eCalendar = Calendar.getInstance();
        eCalendar.setTime(end);
        year = eCalendar.get(Calendar.YEAR);
        month = eCalendar.get(Calendar.MONTH);
        day = eCalendar.get(Calendar.DATE);
        eCalendar.set(year, month, day, 0, 0, 0);
 
        while (sCalendar.before(eCalendar)) {
            list.add(outformat.format(sCalendar.getTime()));
            sCalendar.add(Calendar.DAY_OF_YEAR, 1);
        }
        list.add(outformat.format(eCalendar.getTime()));
 
        return list;
 
    }
 
 
    /**
     * 时间戳转 date
     *
     * @param longDate 时间戳
     * @return
     */
    public static Date getConversionDateByLong(long longDate) {
        //1529398742830
        ZoneId zid = ZoneId.systemDefault();
        LocalDateTime time = LocalDateTime.ofInstant(Instant.ofEpochMilli(longDate), zid);
        ZonedDateTime zdt = time.atZone(zid);
        Date date = Date.from(zdt.toInstant());
        return date;
    }
 
    /**
     * yyyyMMdd 转 yyyy_MM_dd
     *
     * @param strData 时间戳
     * @return
     */
    public static String getdatefor_yyyy_MM_dd(String strData) {
        //1529398742830
        //20180205
        String yyyy_MM_dd = "";
        if (null == strData || strData.length() == 0) {
            return yyyy_MM_dd;
        } else {
            String yyyy = strData.substring(0, 4);
            String mm = strData.substring(4, 6);
            String dd = strData.substring(6, 8);
            yyyy_MM_dd = yyyy + "-" + mm + "-" + dd;
        }
        return yyyy_MM_dd;
    }
 
    public static String getdatefor_HH_mm_ss(String strData) {
        //1529398742830
        //20180205
        String HH_mm_ss = "";
        if (null == strData || strData.length() == 0) {
            return HH_mm_ss;
        } else {
            String HH = strData.substring(0, 2);
            String mm = strData.substring(2, 4);
            String ss = strData.substring(4, 6);
            HH_mm_ss = HH + ":" + mm + ":" + ss;
        }
        return HH_mm_ss;
    }
 
    /**
     * yyyyMMdd
     *
     * @return
     */
    public static String getdatefor_yyyyMMdd() {
        Date newdate = new Date();
        SimpleDateFormat dft = new SimpleDateFormat("yyyyMMdd");
        String date = dft.format(newdate);
        return date;
    }
 
    /**
     * yyyyMMdd
     *
     * @return
     */
    public static String getdatefor_yyyy_MM_dd() {
        Date newdate = new Date();
        SimpleDateFormat dft = new SimpleDateFormat("yyyy-MM-dd");
        String date = dft.format(newdate);
        return date;
    }
 
    //时间戳转换,只取时分秒
    public static Date dataToTimeStampTime(Date time, String dateFormat) {
        String dateString = dateToDateString(time, dateFormat);
        try {
            return getDateFormat(dateFormat).parse(dateString);
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
    }
 
    //获取上周一
    public static Date getLastWeekMonday() {
        Calendar cal = Calendar.getInstance();
        cal.setTime(getDate(getMondayOfThisWeek(), yyyy_MM_dd_EN));
        cal.add(Calendar.DATE, -7);
        return cal.getTime();
    }
 
    //获取上月第一天
    public static Date getFirstDayOfLastMonth() {
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.MONTH, -1);
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        return getDate(dateToDateString(calendar.getTime(), yyyy_MM_dd_EN));
    }
 
 
    /*获取指定年后年*/
    public static String getDateAddYear(String date, int year) {
        DateFormat df = getDateFormat(yyyy);
        try {
            Calendar cal = Calendar.getInstance();
            cal.setTime(df.parse(date));
            cal.add(Calendar.YEAR, year);
            date = df.format(cal.getTime());
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
        return date;
    }
 
    /*
     * 根据时间获取时间内时间点
     * 例:time=2021-08-04 就得到这天内每个小时时间点2021-08-04 00,2021-08-04 01。。。
     *    time=2021-08 就得到这月内每天时间点
     * */
    public static List<String> getTimeLag(String time) {
        List<String> result = new ArrayList<>();
        int length = time.length();
        Calendar cal = Calendar.getInstance();
        String end;
        String dateFormat;
        String df;
        int i;
        if (length == 10) {//日
            end = getDateAddDay(time, 1);
            dateFormat = yyyy_MM_dd_HH_EN;
            df = yyyy_MM_dd_EN;
            i = Calendar.HOUR_OF_DAY;
        } else if (length == 7) {//月
            end = getDateAddMonth(time, 1);
            dateFormat = yyyy_MM_dd_EN;
            df = yyyy_MM_EN;
            i = Calendar.DAY_OF_MONTH;
        } else {//年
            end = getDateAddYear(time, 1);
            dateFormat = yyyy_MM_EN;
            df = yyyy;
            i = Calendar.MONTH;
        }
        cal.setTime(getDate(time, df));
        for (long d = cal.getTimeInMillis(); d < getDate(end, df).getTime(); cal.set(i, cal.get(i) + 1), d = cal.getTimeInMillis()) {
            String format = dateToDateString(new Date(d), dateFormat);
            result.add(format);
        }
        return result;
    }
 
    //根据date取之前第一个分钟为0或5的时间点。例:2021-08-09 15:32:00->2021-08-09 15:30:00,2021-08-09 15:39:00->2021-08-09 15:35:00
    public static Date getFiveMinuteDate(Date date) {
        String dateString = dateToDateString(date, yyyy_MM_dd_HH_mm_EN);
        String minute = dateString.substring(15, 16);
        int i = Integer.parseInt(minute);
        if (i > 0 && i < 5) {
            i = 0;
        } else if (i > 5 && i <= 9) {
            i = 5;
        }
        StringBuilder stringBuffer = new StringBuilder(dateString);
        stringBuffer.replace(15, 16, String.valueOf(i));
        return getDate(stringBuffer.toString(), yyyy_MM_dd_HH_mm_EN);
    }
 
    //获取指定日期hours小时后日期
    public static Date addHours(Date date, int hours) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.HOUR_OF_DAY, hours);
        return calendar.getTime();
    }
 
    //获取去年Date
    public static Date getFirstDayOfLastYear() {
        String lastYear = getDateAddYear(DateUtils.dateToDateString(getDate(), DateUtils.yyyy), -1);
        return DateUtils.getDate(lastYear, DateUtils.yyyy);
    }
}