puzhibing
2023-10-08 22199bbdda579861736420fe26c2873ab0f5d21c
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
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
 
package com.sinata.core.util;
 
import java.text.DateFormat;
import java.text.ParseException;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.*;
 
/**
 * @ClassName DateUtil
 * @Description 日期工具类
 */
public class DateUtils {
 
    // 用来全局控制 上一周,本周,下一周的周数变化
    private int weeks = 0;
    private int MaxDate;// 一月最大天数
    private int MaxYear;// 一年最大天数
 
    // 设置所要取得的格式,需要时在这里设置格式即可
    public static final String StandardDate = "yyyy-MM-dd";
    public static final String MonthDay = "MM-dd";
    public static final String StandardYearMonthDate = "yyyy-MM";
 
    public static final String StandardYearMonthStrDate = "yyyy年MM月";
 
    public static final String StandardDay = "yyyy-MM";
 
    public static final String StandardDateTime = "yyyy-MM-dd HH:mm:ss";
 
    public static final String CompactDateTime = "yyyyMMddHHmmss";
 
    private static final String StandardYear = "yyyy";
 
    private static final String CompactDate = "yyyyMMdd";
 
    private static String MonthDayTime = "MM月dd日 HH时mm分ss秒";
 
    private static String yearMonthDay = "yyyy/MM/dd";
 
    @SuppressWarnings("unused")
    private static final String FileYearMonth = "yyyy/MM";
 
    private static String patternYearMonthDay = "yyyy年MM月dd日";
    private static String patternDate = "yyyy-MM-dd";
    private static String patternDateTime = "yyyy-MM-dd HH:mm:ss";
    public static final String patternDateTimeNote = "yyyy-MM-dd HH:mm";
    public static final String patternDateTimeHhMm = "HH:mm";
 
    // 取得系统当前时间
    public static Date getCurrentDate() {
        return new Date();
    }
 
    // 根据指定格式将输出时间
    public static String getFdate(Date date, String style) {
        SimpleDateFormat dFormat = new SimpleDateFormat(style);
        if (date == null)
            return null;
        String datetime = dFormat.format(date);
        return datetime;
    }
 
    // 获取当天时间并按指定格式输出
    public static String getNowTime(String dateformat) {
        Date now = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat(dateformat);// 可以方便地修改日期格式
        String formatNow = dateFormat.format(now);
        return formatNow;
    }
 
    // 取得系统当前时间并按yyyy-MM-dd格式化输出,
    public static String getNowTime() {
        SimpleDateFormat dFormat = new SimpleDateFormat(StandardDate);
        String datetime = dFormat.format(getCurrentDate());
        return datetime;
    }
 
    // 取得系统当前时间的年并按yyyy格式化输出,
    public static String getYear() {
        Date date = new Date();
        SimpleDateFormat dFormat = new SimpleDateFormat(StandardYear);
        String dateYear = dFormat.format(date);
        return dateYear;
    }
 
    // 取得系统当前时间的年月并按yyyy-MM格式化输出,
    public static String getYMonth() {
        Date date = new Date();
        SimpleDateFormat dFormat = new SimpleDateFormat("yyyy-MM");
        String dateYM = dFormat.format(date);
        return dateYM;
    }
 
    // 将date类型转换为String类型
    public static String dateToString(Date date) {
        String dateStr = "";
        if (date != null) {
            SimpleDateFormat sf = new SimpleDateFormat(StandardDate);
            dateStr = sf.format(date);
        }
        return dateStr;
    }
 
    // 将date类型转换为自定义格式类型
    public static String dateToString(Date date, String formatter) {
        String dateStr = "";
        if (date != null) {
            SimpleDateFormat sf = new SimpleDateFormat(formatter);
            dateStr = sf.format(date);
        }
        return dateStr;
    }
 
    // 将String类型转换为日期类型
    public static Date stringToDate(String str, String style) {
        SimpleDateFormat sdf = new SimpleDateFormat();
        sdf.applyPattern(style);
        Date date = null;
        try {
            date = sdf.parse(str);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }
 
    /**
     * 获取 给定时间的 本周所有时间
     *
     * @param date
     * @return
     */
    public static List<String> getWeekList(String date) {
//        log.info("date value is"+date);
        List<String> strings = new ArrayList<>();
        Calendar c = Calendar.getInstance();
        c.setTime(strToDate(date));
        switch (c.get(Calendar.DAY_OF_WEEK)) {
            case 1:
                strings.add(dateToString(increaseDay(c.getTime(), -6)));
            case 7:
                strings.add(dateToString(increaseDay(c.getTime(), -5)));
            case 6:
                strings.add(dateToString(increaseDay(c.getTime(), -4)));
            case 5:
                strings.add(dateToString(increaseDay(c.getTime(), -3)));
            case 4:
                strings.add(dateToString(increaseDay(c.getTime(), -2)));
            case 3:
                strings.add(dateToString(increaseDay(c.getTime(), -1)));
            case 2:
                strings.add(dateToString(c.getTime()));
        }
        strings.sort(new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return (DateUtils.strToDate(o2).getTime() < DateUtils.strToDate(o1).getTime()) ? -1 : 1;
            }
        });
        return strings;
    }
 
    //将String类型转换为日期类型
    public static Date stringToDateForException(String str, String style) throws Exception {
        SimpleDateFormat sdf = new SimpleDateFormat();
        sdf.applyPattern(style);
        Date date = null;
        if (str == null) {
            return null;
        }
        date = sdf.parse(str);
        return date;
    }
 
    // 根据Private提供的StandarYear返回所需要的格式SimpleDateFormat
    private static SimpleDateFormat getStandardYearFormat() {
        return getDateTimeFormat(StandardYear);
    }
 
    /**
     * 根据参数中定义的日期格式来转换
     *
     * @param pattern
     * @return SimpleDateFormat
     */
    private static SimpleDateFormat getDateTimeFormat(String pattern) {
        SimpleDateFormat sf = new SimpleDateFormat(pattern);
        return sf;
    }
 
    // 返回系统所需时间
    public static String getCurrentYear() {
        SimpleDateFormat sf = getStandardYearFormat();
        return sf.format(getCurrentDate());
    }
 
    /**
     * 得到二个日期间的间隔天数
     */
    public static String getTwoDay(String day1, String day2) {
        SimpleDateFormat myFormatter = new SimpleDateFormat(StandardDate);
        long day = 0;
        try {
            Date date = myFormatter.parse(day1);
            Date mydate = myFormatter.parse(day2);
            day = (date.getTime() - mydate.getTime()) / (24 * 60 * 60 * 1000);
        } catch (Exception e) {
            return "";
        }
        return day + "";
    }
 
    /**
     * 根据一个日期,返回是星期几的字符串
     *
     * @param sdate
     * @return
     */
    public static String getWeek(String sdate) {
        // 再转换为时间
        Date date = DateUtils.strToDate(sdate);
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        // int hour=c.get(Calendar.DAY_OF_WEEK);
        // hour中存的就是星期几了,其范围 1~7
        // 1=星期日 7=星期六,其他类推
        return new SimpleDateFormat("EEEE").format(c.getTime());
    }
 
 
    /**
     * 重构  -- 根据一个时间 返回是 星期几 字符串 ( 上面方法 在不同的服务器系统 返回的是 不同的格式)
     *
     * @param date
     * @return String
     * @auth chenlaichun
     */
    public static String getWeek(Date date) {
        // 再转换为时间
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        // 1=星期日 7=星期六,其他类推
        switch (c.get(Calendar.DAY_OF_WEEK)) {
            case 1:
                return "星期日";
            case 7:
                return "星期六";
            case 6:
                return "星期五";
            case 5:
                return "星期四";
            case 4:
                return "星期三";
            case 3:
                return "星期二";
            case 2:
                return "星期一";
        }
        return "";
    }
 
    /**
     * 将短时间格式字符串转换为时间 yyyy-MM-dd
     *
     * @param strDate
     * @return
     */
    public static Date strToDate(String strDate) {
        SimpleDateFormat formatter = new SimpleDateFormat(StandardDate);
        ParsePosition pos = new ParsePosition(0);
        Date strtodate = formatter.parse(strDate, pos);
        return strtodate;
    }
 
    /**
     * 将短时间格式字符串转换为时间 yyyy-MM
     *
     * @param strDate
     * @return
     */
    public static Date strToDate(String strDate, String formater) {
        SimpleDateFormat formatter = new SimpleDateFormat(formater);
        ParsePosition pos = new ParsePosition(0);
        Date strtodate = formatter.parse(strDate, pos);
        return strtodate;
    }
 
    /*
     * 给一个date 和 时间格式 返回一个特定格式的date  如:得到一个yyyy-MM-dd格式date  需要传入date 和 "yyyy-MM-dd"字符串
     * */
    public static Date getDateByDateAndStrDate(Date date, String strStyle) {
        return DateUtils.stringToDate(DateUtils.getFdate(date, strStyle), strStyle);
    }
 
    /**
     * 两个时间之间的天数
     *
     * @param date1
     * @param date2
     * @return
     */
    public static long getDays(String date1, String date2) {
        if (date1 == null || date1.equals(""))
            return 0;
        if (date2 == null || date2.equals(""))
            return 0;
        // 转换为标准时间
        SimpleDateFormat myFormatter = new SimpleDateFormat(StandardDate);
        Date date = null;
        Date mydate = null;
        try {
            date = myFormatter.parse(date1);
            mydate = myFormatter.parse(date2);
        } catch (Exception e) {
        }
        long day = (date.getTime() - mydate.getTime()) / (24 * 60 * 60 * 1000);
        return day;
    }
 
    // 计算当月最后一天,返回字符串
    public String getDefaultDay() {
        String str = "";
        SimpleDateFormat sdf = new SimpleDateFormat(StandardDate);
 
        Calendar lastDate = Calendar.getInstance();
        lastDate.set(Calendar.DATE, 1);// 设为当前月的1号
        lastDate.add(Calendar.MONTH, 1);// 加一个月,变为下月的1号
        lastDate.add(Calendar.DATE, -1);// 减去一天,变为当月最后一天
 
        str = sdf.format(lastDate.getTime());
        return str;
    }
 
    // 上月第一天
    public String getPreviousMonthFirst() {
        String str = "";
        SimpleDateFormat sdf = new SimpleDateFormat(StandardDate);
 
        Calendar lastDate = Calendar.getInstance();
        lastDate.set(Calendar.DATE, 1);// 设为当前月的1号
        lastDate.add(Calendar.MONTH, -1);// 减一个月,变为下月的1号
        // lastDate.add(Calendar.DATE,-1);//减去一天,变为当月最后一天
 
        str = sdf.format(lastDate.getTime());
        return str;
    }
 
    // 获取当月第一天
    public String getFirstDayOfMonth() {
        String str = "";
        SimpleDateFormat sdf = new SimpleDateFormat(StandardDate);
 
        Calendar lastDate = Calendar.getInstance();
        lastDate.set(Calendar.DATE, 1);// 设为当前月的1号
        str = sdf.format(lastDate.getTime());
        return str;
    }
 
    /**
     * @return Date
     * @Title: getFirstDayOfMonthForDate
     * @Description: 获取当前月的第一天
     * @author guohongjin
     * @date 2016-12-22
     */
 
    public static Date getFirstDayOfMonthForDate() {
        Calendar firstDate = Calendar.getInstance();
        firstDate.set(Calendar.DATE, 1);// 设为当前月的1号
        return firstDate.getTime();
    }
 
    // 获得本周星期日的日期
    public String getCurrentWeekday() {
        weeks = 0;
        int mondayPlus = this.getMondayPlus();
        GregorianCalendar currentDate = new GregorianCalendar();
        currentDate.add(GregorianCalendar.DATE, mondayPlus + 6);
        Date monday = currentDate.getTime();
        return getFdate(monday, StandardDate);
    }
 
    // 获得当前日期与本周日相差的天数
    private int getMondayPlus() {
        Calendar cd = Calendar.getInstance();
        // 获得今天是一周的第几天,星期日是第一天,星期二是第二天......
        int dayOfWeek = cd.get(Calendar.DAY_OF_WEEK) - 1; // 因为按中国礼拜一作为第一天所以这里减1
        if (dayOfWeek == 1) {
            return 0;
        } else {
            return 1 - dayOfWeek;
        }
    }
 
    private static int getMondayPlus(Date date, int days) {
        Calendar cd = Calendar.getInstance();
        cd.setTime(date);
        // 获得今天是一周的第几天,星期日是第一天,星期二是第二天......
        int dayOfWeek = cd.get(Calendar.DAY_OF_WEEK);
        //系统中默认 周末为一周的第一天 如果是周末的话 就设置当前为 7
        if (dayOfWeek == 1) {
            dayOfWeek = 7;
        } else {
            dayOfWeek = dayOfWeek - 1;
        }
        return days - dayOfWeek;
    }
 
    // 获得本周一的日期
    public String getMondayOFWeek() {
        weeks = 0;
        int mondayPlus = this.getMondayPlus();
        GregorianCalendar currentDate = new GregorianCalendar();
        currentDate.add(GregorianCalendar.DATE, mondayPlus);
        Date monday = currentDate.getTime();
        return getFdate(monday, StandardDate);
    }
 
    /**
     * 根据传入的日期 获取本周指定周几的 日期
     *
     * @param date
     * @return
     */
    public static Date getMonthDayOfWeek(Date date, int days) {
        GregorianCalendar currentDate = new GregorianCalendar();
        currentDate.setTime(date);
        currentDate.add(GregorianCalendar.DATE, getMondayPlus(date, days));
        return currentDate.getTime();
    }
 
    // 获得相应周的周六的日期
    public String getSaturday() {
        int mondayPlus = this.getMondayPlus();
        GregorianCalendar currentDate = new GregorianCalendar();
        currentDate.add(GregorianCalendar.DATE, mondayPlus + 7 * weeks + 6);
        Date monday = currentDate.getTime();
        DateFormat df = DateFormat.getDateInstance();
        String preMonday = df.format(monday);
        return preMonday;
    }
 
    // 获得上周星期日的日期
    public String getPreviousWeekSunday() {
        weeks = 0;
        weeks--;
        int mondayPlus = this.getMondayPlus();
        GregorianCalendar currentDate = new GregorianCalendar();
        currentDate.add(GregorianCalendar.DATE, mondayPlus + weeks);
        Date monday = currentDate.getTime();
        DateFormat df = DateFormat.getDateInstance();
        String preMonday = df.format(monday);
        return preMonday;
    }
 
    // 获得上周星期一的日期
    public String getPreviousWeekday() {
        weeks--;
        int mondayPlus = this.getMondayPlus();
        GregorianCalendar currentDate = new GregorianCalendar();
        currentDate.add(GregorianCalendar.DATE, mondayPlus + 7 * weeks);
        Date monday = currentDate.getTime();
        DateFormat df = DateFormat.getDateInstance();
        String preMonday = df.format(monday);
        return preMonday;
    }
 
    // 获得下周星期一的日期
    public String getNextMonday() {
        weeks++;
        int mondayPlus = this.getMondayPlus();
        GregorianCalendar currentDate = new GregorianCalendar();
        currentDate.add(GregorianCalendar.DATE, mondayPlus + 7);
        Date monday = currentDate.getTime();
        DateFormat df = DateFormat.getDateInstance();
        String preMonday = df.format(monday);
        return preMonday;
    }
 
    // 获得下周星期日的日期
    public String getNextSunday() {
 
        int mondayPlus = this.getMondayPlus();
        GregorianCalendar currentDate = new GregorianCalendar();
        currentDate.add(GregorianCalendar.DATE, mondayPlus + 7 + 6);
        Date monday = currentDate.getTime();
        DateFormat df = DateFormat.getDateInstance();
        String preMonday = df.format(monday);
        return preMonday;
    }
 
    // 获得上一周周日的日期 注:周六周日需要减一天 因为外国人周日是每周的第一天
    public static String getNextSundayByDate(Date date) {
        Calendar cd = Calendar.getInstance();
        cd.setTime(date);
        int dayWeek = cd.get(Calendar.DAY_OF_WEEK);//获得当前日期是一个星期的第几天
        if (1 == dayWeek) {
            cd.add(Calendar.DAY_OF_MONTH, -1);
        }
        cd.setFirstDayOfWeek(Calendar.MONDAY);//设置一个星期的第一天
        int day = cd.get(Calendar.DAY_OF_WEEK);//获得当前日期是一个星期的第几天
        cd.add(Calendar.DATE, cd.getFirstDayOfWeek() - day + 6);//根据日历的规则,给当前日期减去星期几与一个星期第一天的差值
        return dateToString(cd.getTime());
    }
 
    @SuppressWarnings("unused")
    private int getMonthPlus() {
        Calendar cd = Calendar.getInstance();
        int monthOfNumber = cd.get(Calendar.DAY_OF_MONTH);
        cd.set(Calendar.DATE, 1);// 把日期设置为当月第一天
        cd.roll(Calendar.DATE, -1);// 日期回滚一天,也就是最后一天
        MaxDate = cd.get(Calendar.DATE);
        if (monthOfNumber == 1) {
            return -MaxDate;
        } else {
            return 1 - monthOfNumber;
        }
    }
 
    // 获得上月最后一天的日期
    public String getPreviousMonthEnd() {
        String str = "";
        SimpleDateFormat sdf = new SimpleDateFormat(StandardDate);
 
        Calendar lastDate = Calendar.getInstance();
        lastDate.add(Calendar.MONTH, -1);// 减一个月
        lastDate.set(Calendar.DATE, 1);// 把日期设置为当月第一天
        lastDate.roll(Calendar.DATE, -1);// 日期回滚一天,也就是本月最后一天
        str = sdf.format(lastDate.getTime());
        return str;
    }
 
    // 获得下个月第一天的日期
    public String getNextMonthFirst() {
        String str = "";
        SimpleDateFormat sdf = new SimpleDateFormat(StandardDate);
 
        Calendar lastDate = Calendar.getInstance();
        lastDate.add(Calendar.MONTH, 1);// 减一个月
        lastDate.set(Calendar.DATE, 1);// 把日期设置为当月第一天
        str = sdf.format(lastDate.getTime());
        return str;
    }
 
    // 获得下个月最后一天的日期
    public String getNextMonthEnd() {
        String str = "";
        SimpleDateFormat sdf = new SimpleDateFormat(StandardDate);
 
        Calendar lastDate = Calendar.getInstance();
        lastDate.add(Calendar.MONTH, 1);// 加一个月
        lastDate.set(Calendar.DATE, 1);// 把日期设置为当月第一天
        lastDate.roll(Calendar.DATE, -1);// 日期回滚一天,也就是本月最后一天
        str = sdf.format(lastDate.getTime());
        return str;
    }
 
    // 获得明年最后一天的日期
    public String getNextYearEnd() {
        String str = "";
        SimpleDateFormat sdf = new SimpleDateFormat(StandardDate);
 
        Calendar lastDate = Calendar.getInstance();
        lastDate.add(Calendar.YEAR, 1);// 加一个年
        lastDate.set(Calendar.DAY_OF_YEAR, 1);
        lastDate.roll(Calendar.DAY_OF_YEAR, -1);
        str = sdf.format(lastDate.getTime());
        return str;
    }
 
    // 获得明年第一天的日期
    public String getNextYearFirst() {
        String str = "";
        SimpleDateFormat sdf = new SimpleDateFormat(StandardDate);
 
        Calendar lastDate = Calendar.getInstance();
        lastDate.add(Calendar.YEAR, 1);// 加一个年
        lastDate.set(Calendar.DAY_OF_YEAR, 1);
        str = sdf.format(lastDate.getTime());
        return str;
 
    }
 
    // 获得本年有多少天
    @SuppressWarnings("unused")
    private int getMaxYear() {
        Calendar cd = Calendar.getInstance();
        cd.set(Calendar.DAY_OF_YEAR, 1);// 把日期设为当年第一天
        cd.roll(Calendar.DAY_OF_YEAR, -1);// 把日期回滚一天。
        int MaxYear = cd.get(Calendar.DAY_OF_YEAR);
        return MaxYear;
    }
 
    private int getYearPlus() {
        Calendar cd = Calendar.getInstance();
        int yearOfNumber = cd.get(Calendar.DAY_OF_YEAR);// 获得当天是一年中的第几天
        cd.set(Calendar.DAY_OF_YEAR, 1);// 把日期设为当年第一天
        cd.roll(Calendar.DAY_OF_YEAR, -1);// 把日期回滚一天。
        int MaxYear = cd.get(Calendar.DAY_OF_YEAR);
        if (yearOfNumber == 1) {
            return -MaxYear;
        } else {
            return 1 - yearOfNumber;
        }
    }
 
    // 获得本年第一天的日期
    public String getCurrentYearFirst() {
        int yearPlus = this.getYearPlus();
        GregorianCalendar currentDate = new GregorianCalendar();
        currentDate.add(GregorianCalendar.DATE, yearPlus);
        Date yearDay = currentDate.getTime();
        DateFormat df = DateFormat.getDateInstance();
        String preYearDay = df.format(yearDay);
        return preYearDay;
    }
 
    // 获得本年最后一天的日期 *
    public String getCurrentYearEnd() {
        Date date = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat(StandardYear);// 可以方便地修改日期格式
        String years = dateFormat.format(date);
        return years + "-12-31";
    }
 
    // 获得上年第一天的日期 *
    public String getPreviousYearFirst() {
        Date date = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat(StandardYear);// 可以方便地修改日期格式
        String years = dateFormat.format(date);
        int years_value = Integer.parseInt(years);
        years_value--;
        return years_value + "-1-1";
    }
 
    // 获得上年最后一天的日期
    public String getPreviousYearEnd() {
        weeks--;
        int yearPlus = this.getYearPlus();
        GregorianCalendar currentDate = new GregorianCalendar();
        currentDate.add(GregorianCalendar.DATE, yearPlus + MaxYear * weeks
                + (MaxYear - 1));
        Date yearDay = currentDate.getTime();
        DateFormat df = DateFormat.getDateInstance();
        String preYearDay = df.format(yearDay);
        this.getThisSeasonTime(11);
        return preYearDay;
    }
 
    // 获得本季度
    public static String getThisSeasonTime(int month) {
        int array[][] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {10, 11, 12}};
        int season = 1;
        if (month >= 1 && month <= 3) {
            season = 1;
        }
        if (month >= 4 && month <= 6) {
            season = 2;
        }
        if (month >= 7 && month <= 9) {
            season = 3;
        }
        if (month >= 10 && month <= 12) {
            season = 4;
        }
        int start_month = array[season - 1][0];
        int end_month = array[season - 1][2];
 
        Date date = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat(StandardYear);// 可以方便地修改日期格式
        String years = dateFormat.format(date);
        int years_value = Integer.parseInt(years);
 
        int start_days = 1;// years+"-"+String.valueOf(start_month)+"-1";//getLastDayOfMonth(years_value,start_month);
        int end_days = getLastDayOfMonth(years_value, end_month);
        String seasonDate = years_value + "-" + start_month + "-" + start_days + " 00:00:00"
                + "," + years_value + "-" + end_month + "-" + end_days + " 23:59:59";
        return seasonDate;
 
    }
 
    /**
     * 获取某年某月的最后一天
     *
     * @param year  年
     * @param month 月
     * @return 最后一天
     */
    private static int getLastDayOfMonth(int year, int month) {
        if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8
                || month == 10 || month == 12) {
            return 31;
        }
        if (month == 4 || month == 6 || month == 9 || month == 11) {
            return 30;
        }
        if (month == 2) {
            if (isLeapYear(year)) {
                return 29;
            } else {
                return 28;
            }
        }
        return 0;
    }
 
    /**
     * 是否闰年
     *
     * @param year 年
     * @return
     */
    public static boolean isLeapYear(int year) {
        return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
    }
 
    /**
     * 计算日期为星期几
     *
     * @param date
     * @return
     * @throws Exception
     */
    public static int currentDateOfweek(Date date) throws Exception {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        int dayForWeek = 0;
        if (c.get(Calendar.DAY_OF_WEEK) == 1) {
            dayForWeek = 7;
        } else {
            dayForWeek = c.get(Calendar.DAY_OF_WEEK) - 1;
        }
        return dayForWeek;
    }
 
    /**
     * 计算两个日期之间相差多少周,包括起始日期,比如起始日期在周六 ,那么这两天一算一周,结束日期在周一,那么这一天也算一周
     *
     * @param startDate
     * @param endDate
     * @return
     * @throws Exception
     */
    public static int getTotalweeks(Date startDate, Date endDate)
            throws Exception {
        long start = startDate.getTime();
        long end = endDate.getTime();
        int startend = (int) ((end - start) / (1000 * 60 * 60 * 24) + 1);
        startend = startend - (7 - currentDateOfweek(startDate)) - 1;
        if ((7 - currentDateOfweek(endDate)) != 0) {
            startend = startend - currentDateOfweek(endDate);
        }
        int w = startend / 7 + 1;
        if ((7 - currentDateOfweek(endDate)) != 0) {
            w = w + 1;
        }
        return w;
    }
 
    /**
     * 根据开始日期计算当前日期是当前年或者当前学期的第几周
     *
     * @param beginDate   开始日期
     * @param currentDate 当前日期
     * @return 周次
     */
    public static Integer getTermWeek(Date beginDate, Date currentDate) {
        if (beginDate == null || currentDate == null) {
            return -1;
        }
        long currentMills = currentDate.getTime();
        long termweekMills = beginDate.getTime();
        if (currentMills < termweekMills) {
            return -1;
        }
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(beginDate);
        int dayofWeek = calendar.get(Calendar.DAY_OF_WEEK);
        // 计算出天数
        float countday = (currentMills - termweekMills) / (1000 * 60 * 60 * 24)
                - (7 - dayofWeek);
        int countweek = (int) (countday / 7) + 1;
        int modcountweek = ((int) countday) % 7;
        if (modcountweek != 0) {
            countweek += 1;
        }
        if (countweek < 1) {
            countweek = 0;
        }
        return countweek;
    }
 
    /**
     * 得到date的月份天数
     *
     * @param date
     * @return
     * @desc
     */
    public static int getMonthDays(Date date) {
        Calendar time = Calendar.getInstance();
        time.clear();
        time.setTime(date);
        int day = time.getActualMaximum(Calendar.DAY_OF_MONTH);// 本月份的天数
        return day;
    }
 
    /**
     * 得到将date增加指定天数后的date
     *
     * @param date       日期
     * @param intBetween 增加的天数
     * @return date 加上intBetween天数后的日期
     */
    public static Date increaseDay(Date date, int intBetween) {
        Calendar calo = Calendar.getInstance();
        calo.setTime(date);
        calo.add(Calendar.DATE, intBetween);
        return calo.getTime();
        // return addDays(date, intBetween);
    }
 
    /**
     * 得到将date增加指定月数后的date
     *
     * @param date       日期
     * @param intBetween 增加的月份
     * @return date 加上intBetween月数后的日期
     */
    public static Date increaseMonth(Date date, int intBetween) {
        Calendar calo = Calendar.getInstance();
        calo.setTime(date);
        calo.add(Calendar.MONTH, intBetween);
        return calo.getTime();
        // return addMonths(date, intBetween);
    }
 
    /**
     * 得到将date增加指定年数后的date
     *
     * @param date       日期
     * @param intBetween 增加的年数
     * @return date加上intBetween年数后的日期
     */
    public static Date increaseYear(Date date, int intBetween) {
        Calendar calo = Calendar.getInstance();
        calo.setTime(date);
        calo.add(Calendar.YEAR, intBetween);
        return calo.getTime();
        // return addYears(date, intBetween);
    }
 
    /**
     * 得到将date增加指定小时数后的date
     *
     * @param date       日期
     * @param intBetween 增加的小时数
     * @return date 加上intBetween小时数后的日期
     */
    public static Date increaseHours(Date date, int intBetween) {
        Calendar calo = Calendar.getInstance();
        calo.setTime(date);
        calo.add(Calendar.HOUR, intBetween);
        return calo.getTime();
        // return addHours(date, intBetween);
    }
 
    public static Date addYears(Date date, int amount) {
        return add(date, 1, amount);
    }
 
    public static Date addMonths(Date date, int amount) {
        return add(date, 2, amount);
    }
 
    public static Date addWeeks(Date date, int amount) {
        return add(date, 3, amount);
    }
 
    public static Date addDays(Date date, int amount) {
        return add(date, 5, amount);
    }
 
    public static Date addHours(Date date, int amount) {
        return add(date, 11, amount);
    }
 
    public static Date addMinutes(Date date, int amount) {
        return add(date, 12, amount);
    }
 
    public static Date addSeconds(Date date, int amount) {
        return add(date, 13, amount);
    }
 
    public static Date addMilliseconds(Date date, int amount) {
        return add(date, 14, amount);
    }
 
    public static Date add(Date date, int calendarField, int amount) {
        if (date == null)
            throw new IllegalArgumentException("The date must not be null");
 
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        c.add(calendarField, amount);
        return c.getTime();
    }
 
    /**
     * 判断一个日期是否在两个日期之间
     *
     * @param startDate 开始日期
     * @param endDate   结束日期
     * @param date      指定日期
     * @return
     * @author 滕辉
     */
    public static boolean between(Date startDate, Date endDate, Date date) {
        if (date == null) {
            return false;
        } else if (startDate == null && endDate == null) {
            return true;
        } else if (startDate != null && startDate.getTime() <= date.getTime()
                && endDate == null) {
            return true;
        } else if (endDate != null && endDate.getTime() >= date.getTime()
                && startDate == null) {
            return true;
        } else if (startDate != null && endDate != null
                && startDate.getTime() <= date.getTime()
                && endDate.getTime() >= date.getTime()) {
            return true;
        } else {
            return false;
        }
    }
 
    /**
     * 获取当前日期是星期几的文字描述
     *
     * @return
     * @author cui
     * @date Jun 26, 2009
     */
    public static String getWeekText() {
        String txt = "星期";
        int weekday;
        Calendar tmp = Calendar.getInstance();
        weekday = tmp.get(Calendar.DAY_OF_WEEK) - 1;
        switch (weekday) {
            case 1:
                txt += "一";
                break;
            case 2:
                txt += "二";
                break;
            case 3:
                txt += "三";
                break;
            case 4:
                txt += "四";
                break;
            case 5:
                txt += "五";
                break;
            case 6:
                txt += "六";
                break;
            case 0:
                txt += "日";
                break;
        }
        return txt;
    }
 
 
    /**
     * @return List<String>
     * @Title: getCurrentYearAndBeforeTen
     * @Description: 获取当前年及前十年
     */
    public static List<String> getCurrentYearAndBeforeTen() {
        List<String> dataList = new ArrayList<String>();
        Calendar tmp = Calendar.getInstance();
        int year = tmp.get(Calendar.YEAR);    //获取年
        for (int y = year; y > (year - 10); y--) {
            dataList.add(y + "");
        }
        return dataList;
    }
//    @SuppressWarnings("static-access")
//    public static void main(String[] args) {
//
//        DateUtils du = new DateUtils();
//        String dt = du.getNowTime();
//        System.out.println(dt);
//        String dd = du.getCurrentYear();
//        System.out.println(dd);
//
//        String df = du.getFdate(new Date(), CompactDate);
//        System.out.println(df);
//        System.out.println("============");
//        String dts = du.dateToString(new Date());
//        System.out.println(dts);
//        String s = "20100101";
//        Date d = du.stringToDate(s, CompactDate);
//        System.out.println(d);
//        DateUtils tt = new DateUtils();
//        System.out.println("获取当天日期:" + tt.getNowTime(StandardDate));
//        System.out.println("获取本周一日期:" + tt.getMondayOFWeek());
//        System.out.println("获取本周日的日期~:" + tt.getCurrentWeekday());
//        System.out.println("获取上周一日期:" + tt.getPreviousWeekday());
//        System.out.println("获取上周日日期:" + tt.getPreviousWeekSunday());
//        System.out.println("获取下周一日期:" + tt.getNextMonday());
//        System.out.println("获取下周日日期:" + tt.getNextSunday());
//        System.out.println("获得相应周的周六的日期:" + tt.getNowTime(StandardDate));
//        System.out.println("获取本月第一天日期:" + tt.getFirstDayOfMonth());
//        System.out.println("获取本月最后一天日期:" + tt.getDefaultDay());
//        System.out.println("获取上月第一天日期:" + tt.getPreviousMonthFirst());
//        System.out.println("获取上月最后一天的日期:" + tt.getPreviousMonthEnd());
//        System.out.println("获取下月第一天日期:" + tt.getNextMonthFirst());
//        System.out.println("获取下月最后一天日期:" + tt.getNextMonthEnd());
//        System.out.println("获取本年的第一天日期:" + tt.getCurrentYearFirst());
//        System.out.println("获取本年最后一天日期:" + tt.getCurrentYearEnd());
//        System.out.println("获取去年的第一天日期:" + tt.getPreviousYearFirst());
//        System.out.println("获取去年的最后一天日期:" + tt.getPreviousYearEnd());
//        System.out.println("获取明年第一天日期:" + tt.getNextYearFirst());
//        System.out.println("获取明年最后一天日期:" + tt.getNextYearEnd());
//        DateUtils dateUtils = new DateUtils();
//        System.out.println("获取本季度第一天到最后一天:" + DateUtils.getThisSeasonTime(6));
//        System.out.println("获取两个日期之间间隔天数2008-12-1~2008-9-29:"
//                + DateUtils.getTwoDay("2008-12-1", "2008-9-29"));
//        System.out.println(du.getFdate(increaseDay(new Date(), 200),
//                CompactDate));
//        System.out.println(getWeekText());
//        List<String> currentYearAndBeforeTen = DateUtils.getCurrentYearAndBeforeTen();
//        System.out.println(currentYearAndBeforeTen);
//        System.out.println(getOldYearMonth());
//    }
 
    /**
     * @param date 时间
     * @param hour 需要比较两个时间相差的小时数
     * @return boolean
     * @Title: isLessThanHour
     * @Description:判断某一时间与当前时间相差小时数是否小于hour
     * @author ransheng
     */
    public static boolean isLessThanHour(Date date, int hour) {
        long millisecond = new Date().getTime() - date.getTime();
        return millisecond < (1000 * 60 * 60 * hour) ? true : false;
    }
 
    /**
     * @param beginDate 开始时间
     * @param endDate   结束时间
     * @return int
     * @Title: getBetweenDateByHour
     * @Description: 获取两个时间相差多少天零多少小时
     */
    public static String getBetweenDateByHour(Date beginDate, Date endDate) {
        //开始时间
        long begDateLong = beginDate.getTime();
        //结束时间+一天的毫秒数
        long endDateLong = endDate.getTime() + 86399000;
        long hour = (endDateLong - begDateLong) / (1000 * 60 * 60);
        long dayNum = hour / 24;
        long hourNum = hour % 24;
        //判断天数是否为0
        if (dayNum >= 0l && hourNum >= 0l) {
            if (dayNum == 0l) {
                if (hourNum == 0l) {
                    return "<font style='color:red;'>时间已过</font>";
                } else {
                    return "<font style='color:red;'>仅剩下" + hourNum + "个小时</font>";
                }
            } else {
                if (hourNum == 0l) {
                    return "还有" + dayNum + "天";
                } else {
                    return "还有" + dayNum + "天" + hourNum + "个小时";
                }
            }
        } else {
            return "<font style='color:red;'>时间已过</font>";
        }
 
    }
 
    ;
 
    /**
     * @param beginDate 开始时间
     * @param endDate   结束时间
     * @return Double
     * @Title: getBetweenDateByHourReturnDouble
     * @Description: 获取两个时间相差多少天零多少小时
     */
    public static Double getBetweenDateByHourReturnDouble(Date beginDate, Date endDate) {
        //开始时间
        long begDateLong = beginDate.getTime();
        //结束时间+一天的毫秒数
        long endDateLong = endDate.getTime() + 86399000;
        long hour = (endDateLong - begDateLong) / (1000 * 60 * 60);
 
        //计算两个时间相差的天数
        return (hour * 1.00) / 24;
 
    }
 
    /**
     * 获取时间的年份
     */
    public static int getYearByTime(Date date) {
        Calendar lastDate = Calendar.getInstance();
        lastDate.setTime(date);
        return lastDate.get(Calendar.YEAR);
    }
 
    /**
     * @param year   年 2014
     * @param montch 月 5,12
     * @param day    日 1,10,20
     * @return Date
     * @Title: getTimeByYmd
     * @Description: 根据年月日生成日期
     */
    public static Date getTimeByYmd(int year, int montch, int day) {
        String date_Str = "" + year;
        if (montch < 10) {
            date_Str = date_Str + "-0" + montch;
        } else {
            date_Str = date_Str + "-" + montch;
        }
        if (day < 10) {
            date_Str = date_Str + "-0" + day;
        } else {
            date_Str = date_Str + "-" + day;
        }
        //初始化一个时间
        Date date = new Date();
        try {
            date = DateUtils.parseDate(date_Str);
        } catch (ParseException e) {
 
            e.printStackTrace();
        }
        return date;
    }
 
 
    /**
     * 获取当前时间的日期yyyy-MM-dd
     *
     * @return
     * @throws ParseException
     * @Title: getNowDate
     * @Description: 方法描述
     */
    public static Date getNowDate() throws ParseException {
        Date now = new Date();
        String time = formatDate(now);
        return parseDate(time);
    }
 
    /**
     * @param date 指定日期
     * @param few  指定相距多少个月,可以为正数or负数,0表示当月月份
     * @param day  指定月份中的天数
     * @param flag 日期格式标志,1表示2015-05-25 00:00:00.0;0表示2015-05-25 59:59:59.0格式
     * @return Date 格式为:yyyy-MM-(月份最后一天)
     * @Title: getDateAfterFewMonth
     * @Description: 获取距离指定日期+(-)n个月
     * @author LuoChao
     * @Date 2015-05-12
     */
    public static Date getDateAfterFewMonth(Date date, Integer few, Integer day, int flag) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        if (null != few)
            calendar.add(Calendar.MONTH, few);
        if (null != day)
            calendar.set(Calendar.DAY_OF_MONTH, day);
        if (flag == 0) {
            calendar.set(Calendar.HOUR_OF_DAY, 0);
            calendar.set(Calendar.MINUTE, 0);
            calendar.set(Calendar.SECOND, 0);
            calendar.set(Calendar.MILLISECOND, 0);
        } else {
            calendar.set(Calendar.HOUR_OF_DAY, 23);
            calendar.set(Calendar.MINUTE, 59);
            calendar.set(Calendar.SECOND, 59);
            calendar.set(Calendar.MILLISECOND, 59);
        }
        return calendar.getTime();
    }
 
 
    public static Date parseDate(String date) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat(patternDate);
        return sdf.parse(date);
    }
 
    public static Date parseDateTime(String dateTime) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat(patternDateTime);
        return sdf.parse(dateTime);
    }
 
    public static String formatDate(Date date) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat(patternDate);
        return sdf.format(date);
    }
 
    public static String formatStrDate(Date date) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat(patternYearMonthDay);
        return sdf.format(date);
    }
 
    public static String formatStrMonthDayTime(Date date) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat(MonthDayTime);
        return sdf.format(date);
    }
 
    public static String formatStryearMonthDay(Date date) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat(yearMonthDay);
        return sdf.format(date);
    }
 
    public static String formatYearAndMonthStrDate(Date date) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat(StandardDay);
        return sdf.format(date);
    }
 
    public static String formatYearMonthStrDate(Date date) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat(StandardYearMonthStrDate);
        return sdf.format(date);
    }
 
    public static String formatYearMonthDate(Date date) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat(StandardYearMonthDate);
        return sdf.format(date);
    }
 
    public static String formatDateTime(Date date) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat(patternDateTime);
        return sdf.format(date);
    }
 
    public static Date parseDateTimeNote(String dateTime) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat(patternDateTimeNote);
        return sdf.parse(dateTime);
    }
 
    public static String formatDateTimeNote(Date date) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat(patternDateTimeNote);
        return sdf.format(date);
    }
 
    /**
     * @param startDate 开始时间
     * @param endDate   结束时间
     * @return long
     * @Title: getDaysByDate
     * @Description: 获取两个时间类型的天数差
     * @author guohongjin
     * @date 2015-08-13
     * @throw ParseException
     */
 
    public static long getDaysByDate(Date startDate, Date endDate) throws ParseException {
        long day = (endDate.getTime() - startDate.getTime()) / (24 * 60 * 60 * 1000);
        return day;
    }
 
 
    /**
     * @param startDate 开始时间
     * @param endDate   结束时间
     * @return Double
     * @Title: getDaysByDateTime
     * @Description: 获取两个时间类型的天数差
     * @author chenlaichun
     * @date 2015-08-13
     */
 
    public static Double getDaysByDateTime(Date startDate, Date endDate) {
        Double day = ((double) (endDate.getTime() - startDate.getTime())) / (24 * 60 * 60 * 1000);
 
        return day;
    }
 
    /**
     * @Title: getMonthByDate
     * @Description: 获取时间的月份
     * @author guohongjin
     * @date 2015-08-14
     * @throw ParseException
     */
 
    public static int getMonthByDate(Date date) throws ParseException {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        return calendar.get(Calendar.MONTH) + 1;
    }
 
    /**
     * @Title: getDayByDate
     * @Description: 获取指定时间的天数
     * @author guohongjin
     * @date 2015-08-14
     * @throw ParseException
     */
 
    public static int getDayByDate(Date date) throws ParseException {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        return calendar.get(Calendar.DATE);
    }
 
    /**
     * 返回指定日期的月的最后一天
     *
     * @param date
     * @return Date
     */
    public static Date getLastDayOfMonth(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(calendar.get(Calendar.YEAR),
                calendar.get(Calendar.MONTH), 1);
        calendar.roll(Calendar.DATE, -1);
        calendar.set(Calendar.HOUR_OF_DAY, 23);
        calendar.set(Calendar.MINUTE, 59);
        calendar.set(Calendar.SECOND, 59);
        return calendar.getTime();
    }
 
    /**
     * 返回当前日期 当天最后一秒
     *
     * @param date
     * @return Date
     */
    public static String getLastNowDate(Date date) {
        String nowDate = DateUtils.dateToString(date);
        nowDate = nowDate + " 23:59:59";
        return nowDate;
    }
 
    /**
     * 获取当天开始时间
     */
    public static String getStartNowDate() {
        String nowDate = DateUtils.dateToString(new Date());
        nowDate = nowDate + " 00:00:00";
        return nowDate;
    }
 
    public static String getStartNowDate(Date date) {
        String nowDate = DateUtils.dateToString(date);
        nowDate = nowDate + " 00:00:00";
        return nowDate;
    }
 
 
    /**
     * 获取当天结束时间
     */
    public static String getLastNowDate() {
        String nowDate = DateUtils.dateToString(new Date());
        nowDate = nowDate + " 23:59:59";
        return nowDate;
    }
 
 
    /**
     * 返回指定年月的月的最后一天
     *
     * @param year
     * @param month
     * @return Date
     */
    public static Date getLastDayOfMonth(Integer year, Integer month) {
        Calendar calendar = Calendar.getInstance();
        if (year == null) {
            year = calendar.get(Calendar.YEAR);
        }
        if (month == null) {
            month = calendar.get(Calendar.MONTH);
        }
        calendar.set(year, month, 1);
        calendar.add(Calendar.MONTH, -1);
        calendar.roll(Calendar.DATE, -1);
        calendar.set(Calendar.HOUR_OF_DAY, 23);
        calendar.set(Calendar.MINUTE, 59);
        calendar.set(Calendar.SECOND, 59);
        return calendar.getTime();
    }
 
    /**
     * 返回指定日期的月的第一天
     *
     * @param date
     * @return
     */
    public static Date getFirstDayOfMonth(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(calendar.get(Calendar.YEAR),
                calendar.get(Calendar.MONTH), 1);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        return calendar.getTime();
    }
 
    /**
     * 返回指定年月的月的第一天
     *
     * @param year
     * @param month
     * @return
     */
    public static Date getFirstDayOfMonth(Integer year, Integer month) {
        Calendar calendar = Calendar.getInstance();
        if (year == null) {
            year = calendar.get(Calendar.YEAR);
        }
        if (month == null) {
            month = calendar.get(Calendar.MONTH);
        }
        calendar.set(year, month, 1);
        calendar.add(Calendar.MONTH, -1);
        return calendar.getTime();
    }
 
    /**
     * 根据传入的 Date 和 日期 获取对应的时间
     *
     * @param date
     * @param day
     * @return
     */
    public static Date getDateByDateAndDay(Date date, Integer day) {
        Calendar calendar = Calendar.getInstance();
        if (Objects.nonNull(date))
            calendar.setTime(date);
        if (Objects.isNull(day))
            day = calendar.DATE;
        calendar.set(Calendar.DATE, day);
        return calendar.getTime();
    }
 
    /**
     * @Title: getHours
     * @Description: 获取指定时间离当前时间差多少小时
     * @author guohongjin
     * @date 2016-06-07
     */
 
    public static long getHours(Date date) {
        long currentDate = new Date().getTime();
        long d = date.getTime();
        return (currentDate - d) / (3600 * 1000);
    }
 
 
    /* 一个日期的后几天的时间, 如:传入一个date 和 int  得到这个date 的后几天  如果int是负数,那么是后几天
     * @param date 日期
     * @param date日期的前n天的日期
     * */
    public static Date getDateAfterDays(Date date, Integer days) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.DATE, days);
        return calendar.getTime();
    }
 
    /**
     * 返回指定日期的上个月的最后一天
     *
     * @param date
     * @return
     */
    public static Date getLastDayOfLastMonth(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) - 1, 1);
        calendar.roll(Calendar.DATE, -1);
        return calendar.getTime();
    }
 
    /**
     * 返回指定日期的上个月的第一天
     *
     * @param date
     * @return
     */
    public static Date getFirstDayOfLastMonth(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) - 1, 1);
        return calendar.getTime();
    }
 
    /**
     * 返回指定日期的下个月的第一天
     *
     * @param date
     * @return
     */
    public static Date getFirstDayOfNextMonth(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1, 1);
        return calendar.getTime();
    }
 
    /**
     * 返回指定日期的下个月的最后一天
     *
     * @param date
     * @return
     */
    public static Date getLastDayOfNextMonth(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1, 1);
        calendar.roll(Calendar.DATE, -1);
        return calendar.getTime();
    }
 
    /**
     * 返回指定日期的下个月的最后一天
     *
     * @param date
     * @return
     */
    public static Date getDayOfNextMonth(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1, 1);
        calendar.roll(Calendar.DATE, -1);
        return calendar.getTime();
    }
 
    /**
     * @param ssNumber 毫秒大小
     * @return String
     * @Title: getDateStringByNumberSs
     * @Description: 根据毫秒大小计算xx天xx小时xx分钟
     * @author guohongjin
     * @date 2015-12-15
     * @throw YnCorpSysException
     */
 
    public static String getDateStringByNumberSs(Long ssNumber) {
 
        long minutiue = ssNumber / (1000 * 60);
        //分钟余额
        long minutiueNum = minutiue % 60;
        //小时
        long hour = (ssNumber) / (1000 * 60 * 60);
        //天数
        long dayNum = hour / 24;
        //小时余额
        long hourNum = hour % 24;
        //判断天数是否为0
 
        if (dayNum == 0l) {
            if (hourNum == 0l) {
                return minutiueNum + "分钟";
            } else {
                return hourNum + "小时" + minutiueNum + "分钟";
            }
        } else {
            if (hourNum == 0l && minutiueNum == 0l) {
                return dayNum + "天";
            } else {
                if (minutiueNum == 0l) {
                    return dayNum + "天" + hourNum + "小时";
                } else {
                    return dayNum + "天" + hourNum + "小时" + minutiueNum + "分钟";
                }
            }
        }
 
    }
 
//    /**
//     * @Title: getLastDateByTime
//     * @Description: 获取指定时间
//     * @param date 时间对象
//     * @return int
//     */
//    public static int  getLastDateByTime(Date date){
////        String str = "";
//        SimpleDateFormat sdf = new SimpleDateFormat(StandardDate);
//        Calendar lastDate = Calendar.getInstance();
//        lastDate.setTimeInMillis(date.getTime());
//        //lastDate.set(Calendar.YEAR, date.getYear());
//        lastDate.set(Calendar.DATE, 1);// 设为当前月的1号
//        //lastDate.set(Calendar.MONTH, date.getMonth());// 加一个月,变为下月的1号
//        lastDate.add(Calendar.DATE, -1);// 减去一天,变为当月最后一天
//        System.out.println(sdf.format(lastDate.getTime()));
//        return lastDate.getTime().getDate();
//
//    }
//    public static void main(String[] args) throws ParseException {
//        try {
////            Date begDate= DateUtils.stringToDateForException("2014-06-04 00:00:00", DateUtils.StandardDateTime);
////            Date endDate= DateUtils.stringToDateForException("2014-05-06 23:00:59", DateUtils.StandardDateTime);
//////            System.out.print(patternDateTimeHhMm);
//////            Date date=DateUtils.parseDateTimeNote("2014-05-06 02:12");
//////            System.out.println(DateUtils.getFdate(date,patternDateTimeHhMm));
////            long days=DateUtils.getDaysByDate(begDate,endDate);
////            System.out.println(days);
//            Date date=new Date();
//            Calendar calendar=Calendar.getInstance();
//            calendar.setTime(date);
//            calendar.getLeastMaximum(Calendar.MONTH);
//            calendar.getActualMaximum(Calendar.MONDAY);
//            System.out.print(calendar.get(Calendar.DATE)+"PPP"+calendar.getActualMaximum(Calendar.MONDAY));
//        } catch (Exception e) {
//            // TODO Auto-generated catch block
//            e.printStackTrace();
//        }
//
//    }
 
//    public static void main2(String[] args) {
//        System.out.println(DateUtils.getDateStringByNumberSs(10000000l));
//    }
 
 
    public static List<Date> getDateRange(Date start, Date end) {
        List<Date> list = new ArrayList<Date>();
        Calendar calendarStart = Calendar.getInstance();
        calendarStart.setTime(start);
        Calendar calendarEnd = Calendar.getInstance();
        calendarEnd.setTime(end);
        getDateList(calendarStart, calendarEnd, list);
        return list;
    }
 
    /**
     * 递归获取时间范围集合
     *
     * @param calendarStart
     * @param calendarEnd
     * @param list
     */
    private static void getDateList(Calendar calendarStart, Calendar calendarEnd, List<Date> list) {
        if (calendarEnd.compareTo(calendarStart) >= 0) {
            list.add(calendarEnd.getTime());
            calendarEnd.add(Calendar.MONTH, -1);//月份减1
            getDateList(calendarStart, calendarEnd, list);
        }
    }
 
    /**
     * 计算开始和结束日期在一个查询时间范围内交集有多少天
     *
     * @param begin
     * @param end
     * @param beginSel
     * @param endSel
     * @return
     * @author yangyuan
     * @date 2016-04-20
     */
    public static int findDateCommonDay(Date begin, Date end, Date beginSel, Date endSel) {
        int days = 0;
        try {
            begin = DateUtils.parseDate(DateUtils.formatDate(begin));
            end = DateUtils.parseDate(DateUtils.formatDate(end));
            beginSel = DateUtils.parseDate(DateUtils.formatDate(beginSel));
            endSel = DateUtils.parseDate(DateUtils.formatDate(endSel));
            long dd = 0l;
            //只有四种情况才能产生交集,分别计算如下:
            if (!beginSel.after(begin) && !end.after(endSel)) {
                //开始时间和结束时间都在查询时间范围内
                dd = (end.getTime() - begin.getTime()) / (24 * 60 * 60 * 1000);
            } else if ((!beginSel.after(begin) && !begin.after(endSel) && !endSel.after(end))) {
                //开始时间在查询时间范围内,结束时间大于查询结束时间
                dd = ((endSel.getTime() - begin.getTime())) / (24 * 60 * 60 * 1000);
            } else if (!begin.after(beginSel) && !beginSel.after(end) && !end.after(endSel)) {
                //开始时间小于查询开始时间,结束时间在查询时间范围内
                dd = ((end.getTime() - beginSel.getTime())) / (24 * 60 * 60 * 1000);
            } else if (!begin.after(beginSel) && !endSel.after(end)) {
                //开始时间和结束时间包含了查询时间范围
                dd = ((endSel.getTime() - beginSel.getTime())) / (24 * 60 * 60 * 1000);
            }
            days = (int) dd;
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return days;
    }
 
    /**
     * @Title: getMinutes
     * @Description: 获取指定时间离当前时间差多少分钟
     * @author guohongjin
     * @date 2016-06-07
     */
 
    public static long getMinutes(Date date) {
        long currentDate = new Date().getTime();
        long d = date.getTime();
        return (currentDate - d) / (60 * 1000);
    }
 
    public static int getHoursByDate(Date date) throws ParseException {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        return calendar.get(Calendar.HOUR_OF_DAY);
    }
 
    public static int getMinutesByDate(Date date) throws ParseException {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        return calendar.get(Calendar.MINUTE);
    }
 
    public static int getSecondByDate(Date date) throws ParseException {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        return calendar.get(Calendar.SECOND);
    }
 
 
//    public static void main(String[] arg){
//        String showDate="2016-12-19";
////        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
////        Date date = DateUtils.strToDate(showDate);
////        showDate = sdf.format
////        Date daa
//
//        System.out.println(DateUtils.getWeekList("2016-12-22").size());
////        for(int i=0;i<3;i++){
////            System.out.println(DateUtils.getNextSundayByDate(new Date()));
////            System.out.println("i____"+i+" size "+stringList.size());
////            Date date = DateUtils.strToDate("2016-12-20");
////            showDate = DateUtils.getNextSundayByDate(DateUtils.increaseDay(date,-1));
////        }
//
//    }
 
    /**
     * 获取当前时间是第几周
     *
     * @return 周次
     */
    public static Integer getYearWeek() {
        Date date = new Date();
        SimpleDateFormat dFormat = new SimpleDateFormat(StandardYear);
        String dateYear = dFormat.format(date);
        Date beginDate = null;
        Date endDate = new Date();
        try {
            beginDate = DateUtils.parseDate(dateYear + "-01-01");
        } catch (ParseException e) {
            e.printStackTrace();
        }
        long endMills = endDate.getTime();
        long beginMills = beginDate.getTime();
        if (endMills < beginMills) {
            return -1;
        }
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(beginDate);
        int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
        // 计算出天数
        float countDay = (endMills - beginMills) / (1000 * 60 * 60 * 24)
                - (7 - dayOfWeek);
        int countWeek = (int) (countDay / 7) + 1;
        int modcountWeek = ((int) countDay) % 7;
        if (modcountWeek != 0) {
            countWeek += 1;
        }
        if (countWeek < 1) {
            countWeek = 0;
        }
        return countWeek;
    }
 
 
    // 过去1年的年份-月份list
    public static List<String> getOldYearMonth() {
        List<String> list = new ArrayList<String>();
        SimpleDateFormat sdf = new SimpleDateFormat(StandardYearMonthDate);
        Calendar lastDate = Calendar.getInstance();
        lastDate.add(Calendar.MONTH, -1);// 减一个月
        String str1 = sdf.format(lastDate.getTime());
        list.add(str1);
        lastDate.add(Calendar.MONTH, -1);// 减一个月
        String str2 = sdf.format(lastDate.getTime());
        list.add(str2);
        lastDate.add(Calendar.MONTH, -1);// 减一个月
        String str3 = sdf.format(lastDate.getTime());
        list.add(str3);
        lastDate.add(Calendar.MONTH, -1);// 减一个月
        String str4 = sdf.format(lastDate.getTime());
        list.add(str4);
        lastDate.add(Calendar.MONTH, -1);// 减一个月
        String str5 = sdf.format(lastDate.getTime());
        list.add(str5);
        lastDate.add(Calendar.MONTH, -1);// 减一个月
        String str6 = sdf.format(lastDate.getTime());
        list.add(str6);
        lastDate.add(Calendar.MONTH, -1);// 减一个月
        String str7 = sdf.format(lastDate.getTime());
        list.add(str7);
        lastDate.add(Calendar.MONTH, -1);// 减一个月
        String str8 = sdf.format(lastDate.getTime());
        list.add(str8);
        lastDate.add(Calendar.MONTH, -1);// 减一个月
        String str9 = sdf.format(lastDate.getTime());
        list.add(str9);
        lastDate.add(Calendar.MONTH, -1);// 减一个月
        String str10 = sdf.format(lastDate.getTime());
        list.add(str10);
        lastDate.add(Calendar.MONTH, -1);// 减一个月
        String str11 = sdf.format(lastDate.getTime());
        list.add(str11);
        lastDate.add(Calendar.MONTH, -1);// 减一个月
        String str12 = sdf.format(lastDate.getTime());
        list.add(str12);
        return list;
    }
 
    /**
     * 根据日期判断日期所在的月份是否是闰月
     *
     * @return
     */
    public static Boolean isLeapMonth(Date date) {
        SimpleDateFormat sdf = new SimpleDateFormat(patternDate);
        String[] dateArray = sdf.format(date).split("-");
        if (dateArray[1].equals("2") && ((Integer.valueOf(dateArray[0]) % 4 == 0 && Integer.valueOf(dateArray[0]) % 100 != 0) || (Integer.valueOf(dateArray[0]) % 400 == 0))) {
            return true;
        }
        return false;
    }
 
    /**
     * 根据年判断是否是闰年
     *
     * @return
     */
    public static Boolean isLeapMonth(int year) {
        if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
            return true;
        }
        return false;
    }
 
    /**
     * @param converDate 需要转换的日期
     * @Title: dateComplete
     * @Description: 给指定时间加入当天最后时间
     * @author guohongjin
     * @date 2017-04-13
     */
 
    public static Date dateComplete(Date converDate) {
        String dateStr = DateUtils.getFdate(converDate, patternDate);
        dateStr = dateStr + " 23:59:59";
        return stringToDate(dateStr, StandardDateTime);
 
    }
 
    public static int compareDate(String DATE1, String DATE2, String format) {
 
        DateFormat df = new SimpleDateFormat(format);
        try {
            Date dt1 = df.parse(DATE1);
            Date dt2 = df.parse(DATE2);
            if (dt1.getTime() > dt2.getTime()) {
                return 1;
            } else if (dt1.getTime() < dt2.getTime()) {
                return -1;
            } else {
                return 0;
            }
        } catch (Exception exception) {
            exception.printStackTrace();
        }
        return 0;
    }
 
    /***
     * 上周或下周的今日
     * @param date 日期
     * @param format 格式,默认为年月日
     * @param lastOrNext 0为上周,1为下周,默认为下周
     * @author xiaobowen
     * @return
     */
    public static String getLastOrNextWeek(Date date, String format, Byte lastOrNext) {
        if (null == format) {
            format = "yyyy-MM-dd";
        }
        Calendar c = Calendar.getInstance();
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        c.setTime(date);
        if (lastOrNext == 0) {
            c.add(Calendar.WEEK_OF_YEAR, -1);
        } else {
            c.add(Calendar.WEEK_OF_YEAR, +1);
        }
        return sdf.format(c.getTime());
    }
 
 
    /***
     * 根据某日期 得到该日期一周的所有时间集合
     * @param date 日期
     * @param format 格式,默认为年月日
     * @author xiaobowen
     * @return List<String>
     */
    public static List<String> getAllWeekDayByDate(String date, String format) {
        if (null == format) {
            format = "yyyy-MM-dd";
        }
 
        List<Date> result = new ArrayList<Date>();
        SimpleDateFormat sdf = new SimpleDateFormat(format); //设置时间格式
        List<String> strList = new ArrayList<>();
        Calendar cal = Calendar.getInstance();
        Date time = null;
        try {
            time = sdf.parse(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        cal.setTime(time);
 
        //判断要计算的日期是否是周日,如果是则减一天计算周六的,否则会出问题,计算到下一周去了
        int dayWeek = cal.get(Calendar.DAY_OF_WEEK);//获得当前日期是一个星期的第几天
        if (1 == dayWeek) {
            cal.add(Calendar.DAY_OF_MONTH, -1);
        }
        //设置一个星期的第一天,按中国的习惯一个星期的第一天是星期一
        cal.setFirstDayOfWeek(Calendar.MONDAY);
        //获得当前日期是一个星期的第几天
        int day = cal.get(Calendar.DAY_OF_WEEK);
        //根据日历的规则,给当前日期减去星期几与一个星期第一天的差值
        cal.add(Calendar.DATE, cal.getFirstDayOfWeek() - day);
        //获得周一的日期
        Calendar startDate = Calendar.getInstance();
        startDate.setTime(cal.getTime());
        //添加第一天进入数组
        strList.add(sdf.format(startDate.getTime()));
        startDate.add(Calendar.DAY_OF_YEAR, 1);
        //改变周一的值为周日
        cal.add(Calendar.DATE, 6);
        //获得周日的日期
        Calendar endDate = Calendar.getInstance();
        endDate.setTime(cal.getTime());
 
        while (startDate.before(endDate)) {
            result.add(startDate.getTime());
            startDate.add(Calendar.DAY_OF_YEAR, 1);
        }
 
        result.forEach(l -> {
            strList.add(sdf.format(l.getTime()));
        });
        //添加最后一天进入数组
        strList.add(sdf.format(endDate.getTime()));
        return strList;
    }
 
    /**
     * 获取指定时间年的第一天
     */
    public static String getFirstTimeOfYear(Date date) {
        SimpleDateFormat dateFormat = new SimpleDateFormat(StandardYear);// 可以方便地修改日期格式
        String years = dateFormat.format(date);
        return years + "-01-01 00:00:00";
    }
 
    /**
     * 获取指定时间年的最后一天
     */
    public static String getLastTimeOfYear(Date date) {
        SimpleDateFormat dateFormat = new SimpleDateFormat(StandardYear);// 可以方便地修改日期格式
        String years = dateFormat.format(date);
        return years + "-12-31 23:59:59";
    }
 
}