DateUtil.java 43.4 KB
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
package com.viontech.utils;

import org.apache.commons.lang3.time.DateUtils;
import org.springframework.context.i18n.LocaleContextHolder;

import java.text.DateFormatSymbols;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

public class DateUtil extends DateUtils {

    public static final String UTC_FULL = "yyyy-MM-dd'T'HH:mm:ss.SSS";
    /**
     * 英文简写(默认)如:2010
     */
    public static String FORMAT_YYYY = "yyyy";
    /**
     * 英文简写(默认)如:2010年
     */
    public static String FORMAT_YYYY_CN = "yyyy年";
    /**
     * 英文简写(默认)如:2010-12-31 24
     */
    public static String FORMAT_YYYY_MM_DD_HH = "yyyy-MM-dd HH";
    /**
     * 英文简写(默认)如:12-31 24
     */
    public static String FORMAT_MM_DD_HH = "MM-dd HH";
    /**
     * 英文简写(默认)如:31 24
     */
    public static String FORMAT_DD_HH = "dd HH";
    /**
     * 英文简写(默认)如:24
     */
    public static String FORMAT_HH = "HH";
    /**
     * 星期的简写 周一 周二 周三 周四等
     */
    public static String FORMAT_DAY_OF_WEEK_SORT_CN = "E";
    public static String FORMAT_WEEK_OF_YEAR = "w";
    /**
     * 英文简写(默认)如:2010-12
     */
    public static String FORMAT_YYYY_MM = "yyyy-MM";
    /**
     * 英文简写(默认)如:2010-12
     */
    public static String FORMAT_YYYY_MM_CN = "yyyy年MM月";
    /**
     * 英文简写(默认)如:12-31
     */
    public static String FORMAT_MM_DD = "MM-dd";
    /**
     * 英文简写带星期(默认)如:12-31(周三)
     */
    public static String FORMAT_MM_DD_E = "MM-dd(E)";
    /**
     * 英文简写(默认)如:31
     */
    public static String FORMAT_DD = "dd";
    /**
     * 英文简写(默认)如:2010-12-01
     */
    public static String FORMAT_SHORT = "yyyy-MM-dd";
    /**
     * 英文全称  如:2010-12-01 23:15
     */
    public static String FORMAT_YYYY_MM_DD_HH_MM = "yyyy-MM-dd HH:mm:ss";
    /**
     * 英文全称  如:2010-12-01 23:15:06
     */
    public static String FORMAT_LONG = "yyyy-MM-dd HH:mm:ss";
    /**
     * 精确到毫秒的完整时间    如:2010-12-01 23:15:06.999
     */
    public static String FORMAT_FULL = "yyyy-MM-dd HH:mm:ss.S";
    /**
     * 中文简写  如:2010年12月01日
     */
    public static String FORMAT_SHORT_CN = "yyyy年MM月dd日";
    /**
     * 中文简写  如:2010年12月01日(周日)
     */
    public static String FORMAT_SHORT_CN_WEEK = "yyyy年MM月dd日(E)";
    public static String FORMAT_SHORT_WEEK = "yyyy-MM-dd(E)";
    /**
     * 中文全称  如:2010年12月01日  23时15分06秒
     */
    public static String FORMAT_LONG_CN = "yyyy年MM月dd日  HH时mm分ss秒";
    /**
     * 精确到毫秒的完整中文时间   如:2010年12月01日  23时15分06秒999毫秒
     */
    public static String FORMAT_FULL_CN = "yyyy年MM月dd日  HH时mm分ss秒SSS毫秒";
    public static String FORMAT_HHMMSS = "HH:mm:ss";
    public static String FORMAT_HHMMSSS = "HH:mm:ss.S";
    public static String FORMAT_HHMM = "HH:mm";
    //设置一周的周几为一周第一天
    public static int FIRST_DAY_OF_WEEK = Calendar.MONDAY; // 中国周一是一周的第一天
    private static DateFormatSymbols dateformatSymbols = new DateFormatSymbols(Locale.CHINA);
    //设置一周的周几为休息日
    private static int[] weekends = null;

    static {
        dateformatSymbols.setShortWeekdays(new String[]{"", "周日", "周一", "周二", "周三", "周四", "周五", "周六"});
    }

    public static void setFirstDayOfWeek(int firstDayOfWeek) {
        FIRST_DAY_OF_WEEK = firstDayOfWeek;
    }

    public static void setWeekend(int[] weekends) {
        DateUtil.weekends = weekends;
    }

    /**
     * 获取上周同期
     *
     * @param date
     *
     * @return 上周同天
     */
    public static Date getLastWeek(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.WEEK_OF_MONTH, -1);
        return calendar.getTime();

    }

    /**
     * 获取上月同期
     *
     * @param date 当日
     *
     * @return
     */
    public static Date getLastMonth(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.MONTH, -1);
        return calendar.getTime();

    }

    /**
     * 获取下月同期
     *
     * @param date 当日
     *
     * @return
     */
    public static Date getNextMonth(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.MONTH, 1);
        return calendar.getTime();

    }

    /**
     * 获取去年同期
     *
     * @param date 当日
     *
     * @return
     */
    public static Date getLastYear(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.YEAR, -1);
        return calendar.getTime();
    }

    /**
     * 获取昨日日期
     *
     * @param date 当日
     *
     * @return
     */
    public static Date getYesterday(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.DAY_OF_YEAR, -1);
        return calendar.getTime();
    }

    /**
     * 获取明天日期
     *
     * @param date 当日
     *
     * @return
     */
    public static Date getTorromow(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.DAY_OF_YEAR, 1);
        return calendar.getTime();
    }


    /**
     * 获取下一小时
     *
     * @param date 日期
     *
     * @return
     */
    public static Date getNextHour(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.HOUR_OF_DAY, 1);
        return calendar.getTime();
    }

    /**
     * 获取前一小时
     *
     * @param date 日期
     *
     * @return
     */
    public static Date getPreviousHour(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.HOUR_OF_DAY, -1);
        return calendar.getTime();
    }

    /**
     * 判断 yesterDay 是否是 today 的昨天
     *
     * @param today     今天日期
     * @param yesterDay 昨天日期
     *
     * @return
     */
    public static boolean isYesterday(Date today, Date yesterDay) {
        return isSameDay(getYesterday(today), yesterDay);
    }

    /**
     * 判断 lastWeekDay 是否是 today 的上周同期
     *
     * @param today       今天日期
     * @param lastWeekDay 上周同期日期
     *
     * @return
     */
    public static boolean isLastWeekDay(Date today, Date lastWeekDay) {
        return isSameDay(getLastWeek(today), lastWeekDay);
    }

    /**
     * 判断 lastMonthDay 是否是 today 的上月同期
     *
     * @param today        今天日期
     * @param lastMonthDay 上月同期
     *
     * @return
     */
    public static boolean isLastMonthDay(Date today, Date lastMonthDay) {
        return isSameDay(getLastMonth(today), lastMonthDay);
    }

    /**
     * 判断 lastYearDay 是否是 today 的去年同期
     *
     * @param today       今天日期
     * @param lastYearDay 去年同期日期
     *
     * @return
     */
    public static boolean isLastYearDay(Date today, Date lastYearDay) {
        return isSameDay(getLastYear(today), lastYearDay);
    }

    /**
     * 判断两个日期是否是同一天
     *
     * @param date1 日期1
     * @param date2 日期2
     *
     * @return
     */
    public static boolean isSameHour(Date date1, Date date2) {
        if (!isSameDay(date1, date2)) {
            return false;
        }
        if (date1.getHours() != date2.getHours()) {
            return false;
        }
        return true;
    }

    /**
     * 判断两个日期是否是同一天
     *
     * @param date1 日期1
     * @param date2 日期2
     *
     * @return
     */
    public static boolean isSameDay(Date date1, Date date2) {
        if (!isSameMonth(date1, date2)) {
            return false;
        }
        if (date1.getDate() != date2.getDate()) {
            return false;
        }
        return true;
    }

    /**
     * 判断两个日期是否是同一周
     *
     * @return
     */
    public static boolean isSameWeek(Date week, Date otherWeek) {
        return isSameDay(getMondayOfWeek(week), getMondayOfWeek(otherWeek));
    }

    /**
     * 判断两个日期是否是同一月
     *
     * @param date1 日期1
     * @param date2 日期2
     *
     * @return
     */
    public static boolean isSameMonth(Date date1, Date date2) {
        if (date1.getYear() != date2.getYear()) {
            return false;
        }
        if (date1.getMonth() != date2.getMonth()) {
            return false;
        }
        return true;
    }

    /***
     * 判断日期2是否是日期1的上周
     * @param date1
     * @param date2
     * @return
     */
    public static boolean isLastWeek(Date date1, Date date2) {
        return isSameWeek(getLastWeek(date1), date2);
    }

    /***
     * 判断日期2是否是日期1的去年同周
     * @param date1
     * @param date2
     * @return
     */
    public static boolean isLastYearWeek(Date today, Date otherDay) {
        //return isSameWeek(getLastYear(date1), date2);
        if (!isSameYear(getLastYear(today), otherDay)) {
            return false;
        }
        return getWeekOfYear(today) == getWeekOfYear(otherDay);
    }

    /***
     /***
     * 判断日期2是否是日期1的上月
     * @param date1
     * @param date2
     * @return
     */
    public static boolean isLastMonth(Date date1, Date date2) {
        return isSameMonth(getLastMonth(date1), date2);
    }

    /***
     * 判断日期2是否是日期1的去年同月
     * @param date1
     * @param date2
     * @return
     */
    public static boolean isLastYearMonth(Date date1, Date date2) {
        return isSameMonth(getLastYear(date1), date2);
    }

    /**
     * 判断两个日期是否是同一季度
     *
     * @param date1 日期1
     * @param date2 日期2
     *
     * @return
     */
    public static boolean isSameSeason(Date date1, Date date2) {
        return getSeason(date1) == getSeason(date2);
    }

    /**
     * 判断 日期2 是否是 日期1的 上一季度
     *
     * @param date1 日期1
     * @param date2 日期2
     *
     * @return
     */
    public static boolean isLastSeason(Date date1, Date date2) {
        return getSeason(date1) == getSeason(date2) + 1;
    }

    /**
     * 判断两个日期是否是同一年
     *
     * @param date1 日期1
     * @param date2 日期2
     *
     * @return
     */
    @SuppressWarnings("deprecation")
    public static boolean isSameYear(Date date1, Date date2) {
        if (date1.getYear() != date2.getYear()) {
            return false;
        }
        return true;
    }

    /**
     * 将HH:mm解析成整点对象
     *
     * @param HMStr
     * @param before true 往前取整  false 往后取整
     *
     * @return
     * @throws ParseException 解析异常
     */
    public static Date parseHMDate2NowTime(String HMStr, boolean before) throws ParseException {
        Calendar calendar = Calendar.getInstance();
        Date HMTime = parse(FORMAT_HHMM, HMStr);
        calendar.setTime(HMTime);
        int hour = calendar.get(Calendar.HOUR_OF_DAY);
        int minute = calendar.get(Calendar.MINUTE);
        int second = calendar.get(Calendar.SECOND);
        int milliSecond = calendar.get(Calendar.MILLISECOND);
        if (before) {
            minute = 0;
            second = 0;
            milliSecond = 0;
        } else {
            minute = 59;
            second = 59;
            milliSecond = 999;
        }
        calendar.set(Calendar.HOUR_OF_DAY, hour);
        calendar.set(Calendar.MINUTE, minute);
        calendar.set(Calendar.SECOND, second);
        calendar.set(Calendar.MILLISECOND, milliSecond);
        return calendar.getTime();
    }

    /**
     * 将日期设置为整点
     *
     * @param date   需要设置的日期
     * @param HMTime 小时分钟信息
     *
     * @return
     */
    public static Date setDayHMS(Date date, Date HMTime) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.HOUR_OF_DAY, HMTime.getHours());
        calendar.set(Calendar.MINUTE, HMTime.getMinutes());
        calendar.set(Calendar.SECOND, HMTime.getSeconds());
        calendar.set(Calendar.MILLISECOND, 0);
        return calendar.getTime();

    }

    /**
     * 将日期设置为对应的时分信息
     *
     * @param date 需要设置的日期
     *
     * @return
     */
    public static Date setDayHM(Date date, String HMTimeStr) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);//HH:mm:ss.S
        Date HMTime = null;
        try {
            HMTime = parse(FORMAT_HHMM, HMTimeStr);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        Calendar hmCalendar = Calendar.getInstance();
        hmCalendar.setTime(HMTime);//HH:mm:ss.S

        calendar.set(Calendar.HOUR_OF_DAY, hmCalendar.get(Calendar.HOUR_OF_DAY));
        calendar.set(Calendar.MINUTE, hmCalendar.get(Calendar.MINUTE));
        calendar.set(Calendar.SECOND, 0);

        return calendar.getTime();
    }

    /**
     * 将日期设置为对应的时分秒
     *
     * @param date 需要设置的日期
     *
     * @return
     */
    public static Date setDayHMS(Date date, String HMSTimeStr) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);//HH:mm:ss.S
        Date HMSTime = null;
        try {
            HMSTime = parse(FORMAT_HHMMSS, HMSTimeStr);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        Calendar hmsCalendar = Calendar.getInstance();
        hmsCalendar.setTime(HMSTime);//HH:mm:ss.S

        calendar.set(Calendar.HOUR_OF_DAY, hmsCalendar.get(Calendar.HOUR_OF_DAY));
        calendar.set(Calendar.MINUTE, hmsCalendar.get(Calendar.MINUTE));
        calendar.set(Calendar.SECOND, hmsCalendar.get(Calendar.SECOND));

        return calendar.getTime();
    }

    /**
     * 日期只取小时数据
     *
     * @param date 需要设置的日期
     *
     * @return
     */
    public static Date setDayH(Date date, String HTimeStr) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);//HH:mm:ss.S
        Date HTime = null;
        try {
            HTime = parse(FORMAT_HH, HTimeStr);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        Calendar hCalendar = Calendar.getInstance();
        hCalendar.setTime(HTime);//HH:mm:ss.S

        calendar.set(Calendar.HOUR_OF_DAY, hCalendar.get(Calendar.HOUR_OF_DAY));
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);

        return calendar.getTime();
    }

    /**
     * 获取时间戳
     */
    public static String getTimeString() {
        Calendar calendar = Calendar.getInstance();
        return format(FORMAT_FULL, calendar.getTime());
    }

    /**
     * 获取日期年份
     *
     * @param date 日期
     *
     * @return
     */
    public static int getYear(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        return calendar.get(Calendar.YEAR);
    }

    /**
     * 功能描述:返回月
     *
     * @param date Date 日期
     *
     * @return 返回月份
     */
    public static int getMonth(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        return calendar.get(Calendar.MONTH) + 1;
    }

//	/**
//	 * 功能描述:返回月
//	 *
//	 * @param date
//	 *            Date 日期
//	 * @return 返回月份
//	 */
//	public static String getMonthStr(Date date) {
//		Calendar calendar = Calendar.getInstance();
//	    calendar.setTime(date);
//	    int monthNum = calendar.get(Calendar.MONTH) + 1;
//	    return   MessageFormat.format(MONTHOFYEAR_STR_FORMAT, monthNum);
//	}

    /**
     * 功能描述:返回日
     *
     * @param date Date 日期
     *
     * @return 返回日份
     */
    public static int getDay(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        return calendar.get(Calendar.DAY_OF_MONTH);
    }

    /**
     * 功能描述:返回小时
     *
     * @param date 日期
     *
     * @return 返回小时
     */
    public static int getHour(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        return calendar.get(Calendar.HOUR_OF_DAY);
    }

    /**
     * 功能描述:返回分
     *
     * @param date 日期
     *
     * @return 返回分钟
     */
    public static int getMinute(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        return calendar.get(Calendar.MINUTE);
    }

    /**
     * 功能描述:返回分
     *
     * @param date 日期
     *
     * @return 返回分钟
     */
    public static int getMinuteOfDay(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        return calendar.get(Calendar.HOUR_OF_DAY) * 60 + calendar.get(Calendar.MINUTE);
    }

    /**
     * 返回秒钟
     *
     * @param date Date 日期
     *
     * @return 返回秒钟
     */
    public static int getSecond(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        return calendar.get(Calendar.SECOND);
    }

    /**
     * 功能描述:返回毫秒
     *
     * @param date 日期
     *
     * @return 返回毫
     */
    public static int getMillis(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        return calendar.get(calendar.MILLISECOND);
    }


    /**
     * 取得当天日期是周几
     *
     * @param date
     *
     * @return
     */
    public static int getDayOfWeek(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        c.setFirstDayOfWeek(FIRST_DAY_OF_WEEK);
        int day_of_week = c.get(Calendar.DAY_OF_WEEK);
        day_of_week -= 1;
        if (day_of_week == 0) {
            day_of_week = 7;
        }
        return day_of_week;
    }

    /**
     * 获取一个月 周一 到 周日 的个数 用count存储
     *
     * @param date
     *
     * @return 下标0 代表周一的天数 下表1代表周二的天数 依次类推
     */
    public static int[] getCountDayOfWeekInMonth(Date date) {
        int[] count = new int[7];
        Date firstDate = getFirstDateOfMonth(date);
        int dayOfWeek = getDayOfWeek(firstDate);
        int dayOfMonth = getPassDayOfMonth(date);
        for (int i = 0; i < dayOfMonth; i++) {
            count[dayOfWeek - 1]++;
            dayOfWeek++;
            if (dayOfWeek > 7) {
                dayOfWeek = 1;
            }
        }
        return count;
    }


    /**
     * 取得一月的第几周
     *
     * @param date
     *
     * @return
     */
    public static int getWeekOfMonth(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        int week_of_year = c.get(Calendar.WEEK_OF_MONTH);
        return week_of_year;
    }

    /**
     * 取得一年的第几周 (中式计算方法,以周一为一周开始)
     *
     * @param date
     *
     * @return
     */
    public static int getWeekOfYear(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        c.setFirstDayOfWeek(FIRST_DAY_OF_WEEK);
        int week_of_year = c.get(Calendar.WEEK_OF_YEAR);
        return week_of_year;
    }


//    /**
//     * 取得一年的第几周,格式为 “第1周” (中式计算方法,以周一为一周开始)
//     *
//     * @param date
//     * @return
//     */
//    public static String getWeekOfYearStr(Date date) {
//        Calendar c = Calendar.getInstance();
//        c.setTime(date);
//        c.setFirstDayOfWeek(FIRST_DAY_OF_WEEK);
//        int week_of_year = c.get(Calendar.WEEK_OF_YEAR);
//        return MessageFormat.format(WEEKOFYEAR_STR_FORMAT, week_of_year);
//    }

    /**
     * 根据日期取得对应周周一日期
     *
     * @param date
     *
     * @return
     */
    public static Date getMondayOfWeek(Date date) {
        Calendar monday = Calendar.getInstance();
        monday.setTime(date);
        monday.setFirstDayOfWeek(FIRST_DAY_OF_WEEK);
        monday.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
        return monday.getTime();
    }

    /**
     * 根据日期取得对应周周日日期
     *
     * @param date
     *
     * @return
     */
    public static Date getSundayOfWeek(Date date) {
        Calendar sunday = Calendar.getInstance();
        sunday.setTime(date);
        sunday.setFirstDayOfWeek(FIRST_DAY_OF_WEEK);
        sunday.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
        return sunday.getTime();
    }

    public static boolean isWeekday(Date date) {
        int dayOfWeek = getDayOfWeek(date);
        if (weekends == null) {
            if (dayOfWeek > 5) {
                return false;
            }
            return true;
        } else {
            for (int weekend : weekends) {
                if (weekend == dayOfWeek) {
                    return false;
                }
            }
            return true;
        }
    }
//	public static boolean isWeekday(Date date){
//		if (getDayOfWeek(date) > 5) {
//			return false;
//		}
//		return true;
//	}

    /**
     * 根据日期取得对应月的第一个相同周几
     *
     * @param date
     *
     * @return
     */
    public static Date getFirstSametWeekOfMonth(Date date) {
        Calendar c = Calendar.getInstance();
        date = setDayMinTime(date);
        c.setTime(date);
        int weekIndex = c.get(Calendar.DAY_OF_WEEK);
        c.set(Calendar.DAY_OF_MONTH, 1);
        while (true) {
            if (weekIndex == c.get(Calendar.DAY_OF_WEEK))
                break;
            c.add(Calendar.DAY_OF_MONTH, 1);
        }
        return c.getTime();
    }

    /**
     * 取得月的剩余天数
     *
     * @param date
     *
     * @return
     */
    public static int getRemainDayOfMonth(Date date) {
        int dayOfMonth = getDayOfMonth(date);
        int day = getPassDayOfMonth(date);
        return dayOfMonth - day;
    }

    /**
     * 取得月已经过的天数
     *
     * @param date
     *
     * @return
     */
    public static int getPassDayOfMonth(Date date) {
        Date monthStart = setDayMinTime(getFirstDateOfMonth(new Date()));
        if (monthStart.after(date))
            return getDayOfMonth(date);

        Date monthEnd = setDayMaxTime(getLastDateOfMonth(new Date()));
        if (monthEnd.before(date))
            return 0;

        Calendar c = Calendar.getInstance();
        c.setTime(new Date());
        return c.get(Calendar.DAY_OF_MONTH);
    }


    /**
     * 取得月天数
     *
     * @param date
     *
     * @return
     */
    public static int getDayOfMonth(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        return c.getActualMaximum(Calendar.DAY_OF_MONTH);
    }

    /**
     * 取得月第一天
     *
     * @param date
     *
     * @return
     */
    public static Date getFirstDateOfMonth(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        c.set(Calendar.DAY_OF_MONTH, c.getActualMinimum(Calendar.DAY_OF_MONTH));
        return c.getTime();
    }

    /**
     * 取得月最后一天
     *
     * @param date
     *
     * @return
     */
    public static Date getLastDateOfMonth(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        c.set(Calendar.DAY_OF_MONTH, c.getActualMaximum(Calendar.DAY_OF_MONTH));
        return c.getTime();
    }

    /**
     * 取得季度第一天
     *
     * @param date
     *
     * @return
     */
    public static Date getFirstDateOfSeason(Date date) {
        return getFirstDateOfMonth(getSeasonDate(date)[0]);
    }

    /**
     * 取得季度最后一天
     *
     * @param date
     *
     * @return
     */
    public static Date getLastDateOfSeason(Date date) {
        return getLastDateOfMonth(getSeasonDate(date)[2]);
    }

    /**
     * 取得季度天数
     *
     * @param date
     *
     * @return
     */
    public static int getDayOfSeason(Date date) {
        int day = 0;
        Date[] seasonDates = getSeasonDate(date);
        for (Date date2 : seasonDates) {
            day += getDayOfMonth(date2);
        }
        return day;
    }

    /**
     * 取得季度剩余天数
     *
     * @param date
     *
     * @return
     */
    public static int getRemainDayOfSeason(Date date) {
        return getDayOfSeason(date) - getPassDayOfSeason(date);
    }

    /**
     * 取得季度已过天数
     *
     * @param date
     *
     * @return
     */
    public static int getPassDayOfSeason(Date date) {
        int day = 0;

        Date[] seasonDates = getSeasonDate(date);

        Calendar c = Calendar.getInstance();
        c.setTime(date);
        int month = c.get(Calendar.MONTH);

        if (month == Calendar.JANUARY || month == Calendar.APRIL
                || month == Calendar.JULY || month == Calendar.OCTOBER) {// 季度第一个月
            day = getPassDayOfMonth(seasonDates[0]);
        } else if (month == Calendar.FEBRUARY || month == Calendar.MAY
                || month == Calendar.AUGUST || month == Calendar.NOVEMBER) {// 季度第二个月
            day = getDayOfMonth(seasonDates[0])
                    + getPassDayOfMonth(seasonDates[1]);
        } else if (month == Calendar.MARCH || month == Calendar.JUNE
                || month == Calendar.SEPTEMBER || month == Calendar.DECEMBER) {// 季度第三个月
            day = getDayOfMonth(seasonDates[0]) + getDayOfMonth(seasonDates[1])
                    + getPassDayOfMonth(seasonDates[2]);
        }
        return day;
    }

    /**
     * 取得季度月
     *
     * @param date
     *
     * @return
     */
    public static Date[] getSeasonDate(Date date) {
        Date[] season = new Date[3];

        Calendar c = Calendar.getInstance();
        c.setTime(date);

        int nSeason = getSeason(date);
        if (nSeason == 1) {// 第一季度
            c.set(Calendar.MONTH, Calendar.JANUARY);
            season[0] = c.getTime();
            c.set(Calendar.MONTH, Calendar.FEBRUARY);
            season[1] = c.getTime();
            c.set(Calendar.MONTH, Calendar.MARCH);
            season[2] = c.getTime();
        } else if (nSeason == 2) {// 第二季度
            c.set(Calendar.MONTH, Calendar.APRIL);
            season[0] = c.getTime();
            c.set(Calendar.MONTH, Calendar.MAY);
            season[1] = c.getTime();
            c.set(Calendar.MONTH, Calendar.JUNE);
            season[2] = c.getTime();
        } else if (nSeason == 3) {// 第三季度
            c.set(Calendar.MONTH, Calendar.JULY);
            season[0] = c.getTime();
            c.set(Calendar.MONTH, Calendar.AUGUST);
            season[1] = c.getTime();
            c.set(Calendar.MONTH, Calendar.SEPTEMBER);
            season[2] = c.getTime();
        } else if (nSeason == 4) {// 第四季度
            c.set(Calendar.MONTH, Calendar.OCTOBER);
            season[0] = c.getTime();
            c.set(Calendar.MONTH, Calendar.NOVEMBER);
            season[1] = c.getTime();
            c.set(Calendar.MONTH, Calendar.DECEMBER);
            season[2] = c.getTime();
        }
        return season;
    }

    /**
     * 1 第一季度 2 第二季度 3 第三季度 4 第四季度
     *
     * @param date
     *
     * @return
     */
    public static int getSeason(Date date) {

        int season = 0;

        Calendar c = Calendar.getInstance();
        c.setTime(date);
        int month = c.get(Calendar.MONTH);
        switch (month) {
            case Calendar.JANUARY:
            case Calendar.FEBRUARY:
            case Calendar.MARCH:
                season = 1;
                break;
            case Calendar.APRIL:
            case Calendar.MAY:
            case Calendar.JUNE:
                season = 2;
                break;
            case Calendar.JULY:
            case Calendar.AUGUST:
            case Calendar.SEPTEMBER:
                season = 3;
                break;
            case Calendar.OCTOBER:
            case Calendar.NOVEMBER:
            case Calendar.DECEMBER:
                season = 4;
                break;
            default:
                break;
        }
        return season;
    }

    /**
     * 取得年第一天
     *
     * @param date
     *
     * @return
     */
    public static Date getFirstDateOfYear(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        c.set(Calendar.DAY_OF_YEAR, c.getActualMinimum(Calendar.DAY_OF_YEAR));
        return setDayMinTime(c.getTime());
    }

    /**
     * 取得年最后一天
     *
     * @param date
     *
     * @return
     */
    public static Date getLastDateOfYear(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        c.set(Calendar.DAY_OF_YEAR, c.getActualMaximum(Calendar.DAY_OF_YEAR));
        return setDayMaxTime(c.getTime());
    }

    /**
     * String转Date
     * 支持:2010-12-01 23:15:06.999
     * 2010-12-01 23:15:06
     * 2010-12-01 23:15
     * 2010-12-01
     *
     * @param dateStr
     *
     * @return
     */
    public static Date dateFormat(String dateStr) throws ParseException {
        if (dateStr.length() == 23) {
            if (dateStr.contains("T")) {
                return parse(UTC_FULL, dateStr);
            } else {
                return parse(FORMAT_FULL, dateStr);
            }
        }
        if (dateStr.length() == 19)
            return DateUtil.parse(FORMAT_LONG, dateStr);
        else if (dateStr.length() == 16)
            return DateUtil.parse(FORMAT_YYYY_MM_DD_HH_MM, dateStr);
        else if (dateStr.length() == 10)
            return DateUtil.parse(FORMAT_SHORT, dateStr);
        else
            return null;
    }

    /**
     * 设置一天的最大值
     *
     * @param date
     *
     * @return
     */
    public static Date setDayMaxTime(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        c.set(Calendar.HOUR_OF_DAY, c.getActualMaximum(Calendar.HOUR_OF_DAY));
        c.set(Calendar.MINUTE, c.getActualMaximum(Calendar.MINUTE));
        c.set(Calendar.SECOND, c.getActualMaximum(Calendar.SECOND));
        c.set(Calendar.MILLISECOND, c.getActualMaximum(Calendar.MILLISECOND));
        return c.getTime();
    }

    /**
     * 设置一天的最小值
     *
     * @param date
     *
     * @return
     */
    public static Date setDayMinTime(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        c.set(Calendar.HOUR_OF_DAY, c.getActualMinimum(Calendar.HOUR_OF_DAY));
        c.set(Calendar.MINUTE, c.getActualMinimum(Calendar.MINUTE));
        c.set(Calendar.SECOND, c.getActualMinimum(Calendar.SECOND));
        c.set(Calendar.MILLISECOND, c.getActualMinimum(Calendar.MILLISECOND));
        return c.getTime();
    }

    /**
     * 当前日期加n毫秒
     *
     * @param date
     * @param num
     *
     * @return
     */
    public static Date dateAddMillisecond(Date date, int num) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        c.add(Calendar.MILLISECOND, num);
        return c.getTime();
    }

    /**
     * 获取两个时间点之间的天(包括开始、结束日期)
     *
     * @param startDate 开始时间
     * @param endDate   结束时间
     *
     * @return
     */
    public static List<Date> getDaysBetweenDates(Date startDate, Date endDate) {
        List<Date> dates = new ArrayList<>();
        Calendar c = Calendar.getInstance();
        c.setTime(startDate);
        while (c.getTime().before(endDate)) {
            dates.add(c.getTime());
            c.add(Calendar.DAY_OF_MONTH, 1);
        }
        dates.add(endDate);
        return dates;
    }

    /**
     * 获取某天所在周的所有日期
     *
     * @param date 日期
     *
     * @return
     */
    public static List<Date> getDaysOfWeek(Date date) {
        Calendar day = Calendar.getInstance();
        day.setTime(date);
        day.setFirstDayOfWeek(FIRST_DAY_OF_WEEK);
        day.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
        Date startDate = day.getTime();
        day.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
        Date endDate = day.getTime();

        List<Date> dates = new ArrayList<>();
        Calendar c = Calendar.getInstance();
        c.setTime(startDate);
        while (c.getTime().before(endDate)) {
            dates.add(c.getTime());
            c.add(Calendar.DAY_OF_MONTH, 1);
        }
        dates.add(endDate);
        return dates;
    }


    /**
     * 将字符串解析成时间,如果无法解析返回null
     *
     * @param sdf
     * @param dateStr
     *
     * @return
     */
    public static Date parseDate(SimpleDateFormat sdf, String dateStr) {
        try {
            return sdf.parse(dateStr);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;

    }

    public static Date maxDate(Date date1, Date date2) {
        if (date1.before(date2)) {
            return date2;
        } else {
            return date1;
        }
    }

    public static Date minDate(Date date1, Date date2) {
        if (date1.before(date2)) {
            return date1;
        } else {
            return date2;
        }
    }

    public static Date UTC2Local(Date date) {
        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyyMMddHHmmss.SSS");
        String utcDate = sdf1.format(date);


        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss.SSS");
        TimeZone utcZone = TimeZone.getTimeZone("UTC");
        sdf.setTimeZone(utcZone);
        Date result = null;
        try {
            result = sdf.parse(utcDate);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return result;
    }

    public static Date local2UTC(Date localDate) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss.SSS");
        TimeZone utcZone = TimeZone.getTimeZone("UTC");
        sdf.setTimeZone(utcZone);
        String utcTime = sdf.format(localDate);
//		System.out.println(utcTime);
        Date result = null;
        try {
            SimpleDateFormat sdf1 = new SimpleDateFormat("yyyyMMddHHmmss.SSS");
            result = sdf1.parse(utcTime);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return result;
    }

    public static List<Date> getMonthDyas(Date date) {
        Date monthStart = getFirstDateOfMonth(date);
        Date monthEnd = getLastDateOfMonth(date);
        Date currentDate = new Date();
        monthEnd = monthEnd.before(currentDate) ? monthEnd : currentDate;
        List<Date> dates = getDaysBetweenDates(monthStart, monthEnd);
        return dates;
    }

    public static String format(String dateFormatStr, Date date) {
        Locale locale = LocaleContextHolder.getLocale();
        return format(dateFormatStr, date, locale);
    }

    public static Date parse(String dateFormatStr, String dateStr) throws ParseException {
        Locale locale = LocaleContextHolder.getLocale();
        return parse(dateFormatStr, dateStr, locale);
    }

    public static Date parse(String dateFormatStr, String dateStr,int offset) throws ParseException {
        Locale locale = LocaleContextHolder.getLocale();
        Date parse = parse(dateFormatStr, dateStr, locale);
        return DateUtils.addHours(parse, offset);
    }

    public static String format(String dateFormatStr, Date date, Locale locale) {

        SimpleDateFormat sdf = null;
        if (locale != null && !"zh".equals(locale.getLanguage())) {//如果不是中文用其默认的格式 否则使用中文的自定义格式
            sdf = new SimpleDateFormat(dateFormatStr, locale);
        } else {
            sdf = new SimpleDateFormat(dateFormatStr, dateformatSymbols);
        }

        return sdf.format(date);
    }

    public static Date parse(String dateFormatStr, String dateStr, Locale locale) throws ParseException {

        SimpleDateFormat sdf = null;
        if (locale != null && !"zh".equals(locale.getLanguage())) {//如果不是中文用其默认的格式 否则使用中文的自定义格式
            sdf = new SimpleDateFormat(dateFormatStr, locale);
        } else {
            sdf = new SimpleDateFormat(dateFormatStr, dateformatSymbols);
        }
        return sdf.parse(dateStr);
    }

    /**
     * 指定格式化日期格式,比较两个字符串日期的大小
     *
     * @param dateFormatStr
     * @param DATE1
     * @param DATE2
     *
     * @return 1:date1>date2  -1 date1 < date2
     */
    public static int compareDate(String dateFormatStr, String DATE1, String DATE2) {
        SimpleDateFormat sdf = new SimpleDateFormat(dateFormatStr);
        try {
            Date dt1 = sdf.parse(DATE1);
            Date dt2 = sdf.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 dt1
     * @param dt2
     *
     * @return 1:date1>date2  -1 date1 < date2
     */
    public static int compareDate(Date dt1, Date dt2) {
        try {
            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 min           向后推的时间
     * @param dateFormatStr 需要生成的日期格式
     *
     * @return
     */
    public static String DateBlockFormatStr(Date date, int min, String dateFormatStr) {
        Date dt2 = addMinutes(date, min);
        return format(dateFormatStr, date) + "-" + format(dateFormatStr, dt2);
    }

    /**
     * 作废,中心判断数据是否在营业时间
     * 判断时间是否在时间范围内(只比较小时、分钟)
     *
     * @param date
     * @param startDate
     * @param endDate
     *
     * @return
     */
    public static boolean isInOpenTime(Date date, Date startDate, Date endDate) {

        boolean flag = true;
        if (flag) {
            return isInBusiness(date, startDate, endDate);
        }
        Calendar date_c = Calendar.getInstance();
        date_c.setTime(date);
        int year = date_c.get(Calendar.YEAR);
        int month = date_c.get(Calendar.MONTH);
        int day = date_c.get(Calendar.DAY_OF_MONTH);
        int hour = date_c.get(Calendar.HOUR_OF_DAY);

        //开始、结束日期设置统一的天级以上的日期
        Calendar start_c = Calendar.getInstance();
        start_c.setTime(startDate);
        start_c.set(year, month, day);
        int start_hour = start_c.get(Calendar.HOUR_OF_DAY);
        startDate = start_c.getTime();

        Calendar end_c = Calendar.getInstance();
        end_c.setTime(endDate);
        end_c.set(year, month, day);
        endDate = end_c.getTime();
        //跨天数据特殊处理
        if (endDate.before(startDate) || endDate.equals(startDate)) {
            Calendar end_n = Calendar.getInstance();
            end_n.setTime(endDate);
            end_n.add(Calendar.DAY_OF_MONTH, 1);
            endDate = end_n.getTime();
        }


        if (DateUtil.compareDate(date, endDate) <= 0) {
            if (DateUtil.compareDate(date, startDate) >= 0)
                return true;
            else {
                if (hour == start_hour) //开业时间同一个小时的数据,统计到小时数据中
                    return true;
                else
                    return false;
            }
        }
        return false;
    }

    public static boolean isInBusiness(Date counttime, Date startTime, Date endTime) {
        Calendar counttimeCalendar = Calendar.getInstance();
        counttimeCalendar.setTime(counttime);
        Calendar startTimeCalendar = Calendar.getInstance();
        startTimeCalendar.setTime(startTime);

        int counttimeHour = counttimeCalendar.get(Calendar.HOUR_OF_DAY);
        int counttimeMinute = counttimeCalendar.get(Calendar.MINUTE);
        int startTimeHour = startTimeCalendar.get(Calendar.HOUR_OF_DAY);
        int startTimeMinute = startTimeCalendar.get(Calendar.MINUTE);

        Calendar endTimeCalendar = Calendar.getInstance();
        endTimeCalendar.setTime(endTime);
        int endTimeHour = endTimeCalendar.get(Calendar.HOUR_OF_DAY);
        int endTimeMinute = endTimeCalendar.get(Calendar.MINUTE);

        if (startTimeHour == endTimeHour && startTimeMinute == endTimeMinute) {
            return true;
        } else if (startTimeHour < endTimeHour || (startTimeHour == endTimeHour && startTimeMinute < endTimeMinute)) {//如果是正常的营业
            if (counttimeHour < startTimeHour) {//如果小时小于营业时间 不用比分钟了
                return false;
            } else if (counttimeHour == startTimeHour) {
                if (counttimeMinute < startTimeMinute) {
                    return false;
                }
            }
            if (counttimeHour > endTimeHour) {//如果小时大于营业时间 也不用比分钟了
                return false;
            } else if (counttimeHour == endTimeHour) {
                if (counttimeMinute > endTimeMinute) {
                    return false;
                }
            }
            return true;
        } else {//如果是跨天的营业时间
            if (counttimeHour > startTimeHour) {//如果小时小于营业时间 不用比分钟了
                return true;
            } else if (counttimeHour == startTimeHour) {
                if (counttimeMinute > startTimeMinute) {
                    return true;
                }
            }
            if (counttimeHour < endTimeHour) {
                return true;
            } else if (counttimeHour == endTimeHour) {
                if (counttimeMinute < endTimeMinute) {
                    return true;
                }
            }
            return false;
        }
    }

    public static String getStringUTC(String dateTime) {
        try {
            Date date = dateFormat(dateTime);
            Calendar cal = Calendar.getInstance(Locale.CHINA);
            cal.setTime(date);
            int zoneOffset = cal.get(Calendar.ZONE_OFFSET);
            int dstOffset = cal.get(Calendar.DST_OFFSET);
            cal.add(Calendar.MILLISECOND, -(zoneOffset + dstOffset));
            return format(FORMAT_FULL, cal.getTime());
        } catch (ParseException e) {
            System.out.println("字符串格式不正确yyyy-MM-dd HH:mm:ss.S");
        }
        return "error";
    }

    /**
     * 获取服务器UTC时间
     *
     * @return
     */
    public static Calendar getCurrentUTC() {
        Calendar cal = Calendar.getInstance(Locale.CHINA);
        int zoneOffset = cal.get(Calendar.ZONE_OFFSET);
        int dstOffset = cal.get(Calendar.DST_OFFSET);
        cal.add(Calendar.MILLISECOND, -(zoneOffset + dstOffset));
        return cal;
    }

}