dangsn
2024-06-11 b6dee87c91bfdcb68fcc456c9a2ec46b2ed7cbe3
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
package com.vci.starter.web.util;
 
import org.apache.commons.lang3.StringUtils;
 
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
 
 
/**
 * 时间工具类
 * 暂时不用JDK8的日期格式
 * @author weidy
 */
public  class VciDateUtil {
 
    /**
     * 默认日期格式
     */
    private static final String DEFAULT_FORMAT = "yyyy-MM-dd HH:mm:ss.SSS";
 
    /**
     * 日期时间
     */
    public static final String DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
 
    /**
     * 日期时间-不含符号
     */
    public static final String DateTimeFormatStr = "yyyyMMddHHmmss";
 
    /**
     * 日期时间含毫秒,不含符号
     */
    public static final String DateTimeMillFormatStr = "yyyyMMddHHmmssSSS";
 
    /**
     * 日期时间含毫秒
     */
    public static final String DateTimeMillFormat = "yyyy-MM-dd HH:mm:ss.SSS";
 
    /**
     * 日期格式
     */
    public static final String DateFormat = "yyyy-MM-dd";
 
    /**
     * 时间格式
     */
    public static final String TimeFormat = "HH:mm:ss";
 
    /**
     * 默认构造函数
     */
    private VciDateUtil() {
    }
 
    /**
     * 字符串转换成日期 如果转换格式为空,则利用默认格式进行转换操作
     * 
     * @param str
     *            字符串
     * @param format
     *            日期格式
     * @return 日期
     * @throws ParseException
     */
    public static Date str2Date(String str, String format) throws Exception {
        if (null == str || "".equals(str) || str.equals("null")) {
            return null;
        }
        // 如果没有指定字符串转换的格式,则用默认格式进行转换
        if (null == format || "".equals(format) || format.equals("null")) {
            format = DEFAULT_FORMAT;
        }
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        Date date = null;
        try {
            date = sdf.parse(str);
            return date;
        } catch (ParseException e) {
            throw new Exception(e);
        }
    }
 
    /**
     * 获取当前周的周一
     * @return 周一的日期
     */
    public static Date getCurrentMonday(){
        return getCurrentWeekDay(2);
    }
 
    /**
     * 获取当前周的某一天
     * @param dayOfWeek 从周日开始为1,周一为2,一次推算
     * @return 日期
     */
    public static Date getCurrentWeekDay(int dayOfWeek){
        if(dayOfWeek>7){
            dayOfWeek = 7;
        }
        if(dayOfWeek<1){
            dayOfWeek = 1;
        }
        Date date = new Date();
        Calendar calendar = Calendar.getInstance();
 
        calendar.setTime(date);
        calendar.set(Calendar.DAY_OF_WEEK, dayOfWeek);
        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();
    }
 
    /**
     * 获取当前周的周五
     * @return 日期
     */
    public static Date getCurrentFriday(){
        return getCurrentWeekDay(6);
    }
 
    /**
     * 日期转换为字符串
     * 
     * @param date
     *            日期
     * @param format
     *            日期格式
     * @return 字符串
     */
    public static String date2Str(Date date, String format) {
        if (null == date) {
            return null;
        }
        if (format == null || format.trim().length() == 0) {
            format = DEFAULT_FORMAT;
        }
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        return sdf.format(date);
    }
 
    /**
     * 时间戳转换为字符串
     * 
     * @param time 时间戳
     * @return 字符串
     */
    public static String timestamp2Str(Timestamp time) {
        Date date = null;
        if (null == time) {
            return null;
        }
        if (null != time) {
            date = new Date(time.getTime());
        }
        return date2Str(date, DEFAULT_FORMAT);
    }
 
    /**
     * 字符串转换时间戳
     * 
     * @param str 字符串
     * @return 时间戳
     * @throws Exception 字符串的格式出现错误的时候抛出异常
     */
    public static Timestamp str2Timestamp(String str) throws Exception {
        if (str == null || str.trim().length() == 0) {
            return null;
        }
        Date date = str2Date(str, DEFAULT_FORMAT);
        return new Timestamp(date.getTime());
    }
 
 
 
    /**
     * 对比两个日期的大小
     * 
     * @param date 时间对象1
     * @param date1 时间对象2
     * @return
     */
    public static String compareDate(String date, String date1)
            throws Exception {
        if (date == null || date.trim().length() == 0 || date1 == null
                || date1.trim().length() == 0) {
            throw new Exception("传入compareDate的参数为空");
        }
        try {
            long time = str2Date(date, DateFormat).getTime();
            long time1 = str2Date(date1, DateFormat).getTime();
            if (time == time1) {
                return "=";
            }
            if (time < time1) {
                return "<";
            }
            if (time > time1) {
                return ">";
            }
            else {
                return "";
            }
        } catch (Exception e) {
            throw e;
        }
    }
 
    /**
     * 时间对比
     * @param date 日期对象1
     * @param date1 日期对象2
     * @return 对比的结果
     */
    public static String compareDate(Date date, Date date1) {
        if (date == null || date1 == null) {
            return "";
        }
        long time = date.getTime();
        long time1 = date1.getTime();
        if (time == time1) {
            return "=";
        }
        if (time < time1) {
            return "<";
        }
        if (time > time1) {
            return ">";
        }
        else {
            return "";
        }
    }
 
    /**
     * 在时间戳上加分钟
     * 
     * @param date 日期字符串
     * @param minute 分钟
     * @return 添加后日期值
     * @throws Exception 日期字符串的格式错误时会抛出错误
     */
    public static String dateTimeAddMinutes(String date, int minute)
            throws Exception {
        String ret = "";
        if (date == null || date.equals("")) {
            date = date2Str(getNow(), DEFAULT_FORMAT);
        }
        if (minute == 0) {
            ret = date;
        }
        else {
            Date d = VciDateUtil.str2Date(date, DateTimeFormat);
            Calendar cal = Calendar.getInstance();
            cal.setTime(d);
            cal.add(Calendar.MINUTE,minute);
            return date2Str(cal.getTime(), DateTimeFormat);
        }
        return ret;
    }
 
    /**
     * 在时间上加天数
     * 
     * @param date 日期字符串
     * @param dayCount 天数,可以为负数
     * @return 添加后的日期值
     * @throws Exception 日期字符串的格式错误
     */
    public static Date getDateAddDay(String date, int dayCount)
            throws Exception {
        if (date == null || date.equals("") || date.equals("null")) {
            return getNow();
        }
        else {
            if (dayCount == 0) {
                return str2Date(date, DateFormat);
            }
            else {
                Date d = str2Date(date, DateFormat);
                Calendar cal = Calendar.getInstance();
                cal.setTime(d);
                cal.add(Calendar.DAY_OF_MONTH,dayCount);
                return cal.getTime();
            }
        }
    }
 
    /**
     * 在时间上加天数
     * 
     * @param date 日期对象
     * @param dayCount 天数
     * @return 添加后的日期对象
     */
    public static Date getDateAddDay(Date date, int dayCount) {
        if (dayCount == 0) {
            return date;
        }
        else {
            Calendar cal = Calendar.getInstance();
            cal.setTime(date);
            cal.add(Calendar.DAY_OF_MONTH,dayCount);
            return cal.getTime();
        }
    }
 
    /**
     * 日期相减
     * 
     * @param beginDateStr 开始日期字符串
     * @param endDateStr 结束日期字符串
     * @return 相减后日期值
     */
    public static long getDaySub(String beginDateStr, String endDateStr) {
        if (beginDateStr == null || beginDateStr.trim().equals("")
                || endDateStr == null || endDateStr.trim().equals("")) {
            return 0;
        }
        long day = 0;
        SimpleDateFormat format = new SimpleDateFormat(DateFormat);
        Date beginDate;
        Date endDate;
        try {
            beginDate = format.parse(beginDateStr);
            endDate = format.parse(endDateStr);
            day = (endDate.getTime() - beginDate.getTime())
                    / (24 * 60 * 60 * 1000);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return day;
    }
 
    /**
     * 获取相关日期相减
     * @param date 开始日期
     * @param date1 结束日期
     * @return 相减的差额
     */
    public static long getDaySub(Date date, Date date1) {
        return (date.getTime() - date1.getTime()) / (24 * 60 * 60 * 1000);
    }
 
 
    /**
     * 在时间上加上某个数。不能使用getTime后然后添加数,会造成long的溢出
     * @param d 原始日期对象
     * @param addDayType 添加的类型,必须是Calendar.YEAR,Calendar.MOUTH,Calendar.DAY_OF_YEAR,Calendar.DAY_OF_WEEK其中一个
     * @param addCount 要添加的数,可以是负数
     * @return 添加获取减去的日期
     */
    public static Date addOrSubDate(Date d, int addDayType, int addCount ) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(d);
        cal.add(addDayType,addCount);
        return cal.getTime();
    }
 
    /**
     * 获取当期时间
     * 
     * @return 当前日期
     */
    public static Date getNow() {
        return new Date();
    }
 
    /**
     * 获取当前时间的字符串格式
     * 
     * @return 当前日期的字符串形式
     */
    public static String getNowString() {
        return getNowString(DEFAULT_FORMAT);
    }
 
    /**
     * 获取当前时间的字符串格式(可自定义时间格式)
     * 
     * @param simpleDateFormat
     *            时间的格式
     * @return 指定格式的当前日期字符串
     */
    public static String getNowString(String simpleDateFormat) {
        Date currentTime = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat(simpleDateFormat);
        return formatter.format(currentTime);
    }
 
    /**
     * 获取当前时间(可自定义时间格式)
     * 
     * @param simpleDateFormat
     *            时间格式
     * @return 根据指定格式的当前日期对象
     * @throws Exception 日期格式字符串的内容错误时抛出异常
     */
    public static Date getNow(String simpleDateFormat) throws Exception {
        return str2Date(getNowString(simpleDateFormat), simpleDateFormat);
    }
 
    /**
     * 获取剩下的时间
     * 
     * @param oldtime 原始时间
     * @param newTime 结束时间
     * @return 时间余额,负数表示已经超时了
     */
    public static String getCountdown(String oldtime, String newTime) {
        if (oldtime == null || oldtime.trim().equals("") || newTime == null
                || newTime.equals("")) {
            return "";
        } else {
            try {
                Date date1 = new SimpleDateFormat(DateTimeFormat)
                        .parse(oldtime);
                Date date2 = new SimpleDateFormat(DateTimeFormat)
                        .parse(newTime);
                long l = date1.getTime() - date2.getTime() > 0 ? date1
                        .getTime() - date2.getTime() : date2.getTime()
                        - date1.getTime();
                long d = 0;
                long yushu = l;
                long h = 0;
                long m = 0;
                if (l > (24 * 60 * 60 * 1000)) {
                    yushu = l % (24 * 60 * 60 * 1000);
                    d = (l - yushu) / (24 * 60 * 60 * 1000);
                }
                if (yushu > (60 * 60 * 1000)) {
                    h = (yushu - yushu % (60 * 60 * 1000)) / (60 * 60 * 1000);
                    yushu = yushu % (60 * 60 * 1000);
                }
                if (yushu > (60 * 1000)) {
                    m = (yushu - yushu % (60 * 1000)) / (60 * 1000);
                }
                if (date1.getTime() - date2.getTime() < 0) {
                    return "已经超期" + d + "天" + h + "小时" + m + "分";
                }
                else {
                    return "还剩下" + d + "天" + h + "小时" + m + "分";
                }
            } catch (Exception te) {
                return "";
            }
        }
    }
 
    /**
     * 两个时间相减
     * 
     * @param oldTime 原时间
     * @param newTime 结束时间
     * @return 相减后的毫秒数
     */
    public static long getDateDiffer(String oldTime, String newTime) {
        if (oldTime == null || oldTime.trim().equals("") || newTime == null
                || newTime.equals("")) {
            return 0;
        } else {
            try {
                Date date1 = new SimpleDateFormat(DateTimeFormat)
                        .parse(oldTime);
                Date date2 = new SimpleDateFormat(DateTimeFormat)
                        .parse(newTime);
                return date1.getTime() - date2.getTime();
            } catch (Exception e) {
                return 0;
            }
        }
    }
 
    /**
     * 获取某年一共有多少周
     * 
     * @param year 年份
     * @return 某年的周数
     */
    public static int getWeeks(int year) {
        if (year == 0) {
            return year;
        }
        int week = 0;
        int days = 365;
        if (year % 400 == 0 || year % 4 == 0 && year % 100 != 0) {
            days = 366;
        }
        week = days / 7;
        return week;
    }
 
    /**
     * 传入的时间在这一年是第几周
     * 
     * @param date 日期对象
     * @return 日期所在的周数
     */
    public static int getWeekOnDate(Date date) {
        GregorianCalendar g = new GregorianCalendar();
        g.setTime(date);
        if (isSunday(date)) {
            return g.get(Calendar.WEEK_OF_YEAR) - 1;
        }
        return g.get(Calendar.WEEK_OF_YEAR);// 获得周数
    }
 
    /**
     * 获取某年中某周的日历对象
     * 
     * @param year 年份
     * @param week 周数
     * @return 日历对象
     * @throws Exception 在年份的字符串格式错误时抛出错误
     */
    public static Calendar getCalendarFromWeek(String year, int week)
            throws Exception {
        Date newDate;
        newDate = str2Date(year + "-01-01", DateFormat);
        Calendar caleNew = Calendar.getInstance();
        caleNew.setTime(newDate);
        caleNew.add(Calendar.WEEK_OF_YEAR, week - 1);
        return caleNew;
    }
 
    /**
     * 获取某年中某周的日期数组
     * 
     * @param year 年份
     * @param week 周数
     * @return 某一周的整个日期
     */
    public static String[] getDaysInWeek(int year, int week) {
        String[] thisWeek = new String[7];
        try {
            GregorianCalendar gc = (GregorianCalendar) getCalendarFromWeek(
                    String.valueOf(year) + "-01-01", week);
            for (int i = 0; i < 7; i++) {
                Calendar myCale = Calendar.getInstance();
                myCale.setTime(gc.getTime());
                myCale.set(Calendar.DATE,
                        gc.get(Calendar.DATE) - gc.get(Calendar.DAY_OF_WEEK)
                                + i + 2);
                thisWeek[i] = date2Str(myCale.getTime(), DateFormat);
            }
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return thisWeek;
    }
 
    /**
     * 判断今天是不是周日
     * 
     * @return true表示为周日,false表示为不是周日
     */
    public static boolean isSunday() {
        return isSunday(new Date());
    }
 
    /**
     * 判断某天是不是周日
     * 
     * @param date 日期对象
     * @return true表示为周日,false表示为不是周日
     */
    public static boolean isSunday(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        int week = calendar.get(Calendar.DAY_OF_WEEK) - 1;
        if (week == 0) {
            return true;
        }
        else {
            return false;
        }
    }
 
    /**
     * 判断某天是否周末
     * 
     * @param date 日期对象
     * @return true表示为周末,false表示为不是周末
     */
    public static boolean isWeekend(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        int week = calendar.get(Calendar.DAY_OF_WEEK) - 1;
        if (week == 0 || week == 1) {
            return true;
        }
        else {
            return false;
        }
    }
 
    /**
     * 判断某天是否为周5
     * 
     * @param date 日期对象
     * @return true表示为周五,false表示为不是周五
     */
    public static boolean isFriday(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        int week = calendar.get(Calendar.DAY_OF_WEEK) - 1;
        if (week == 5) {
            return true;
        }
        else {
            return false;
        }
    }
 
    /**
     * 判断某天是否为月末
     * 
     * @param date 日期
     * @return true表示为月末,false表示为不是月末
     */
    public static boolean isMouthEnd(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
        int endMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
        if (endMonth == dayOfMonth) {
            return true;
        } else {
            return false;
        }
    }
 
    /**
     * 判断某天是否为季末
     * 
     * @param date 日期对象
     * @return true表示为季末,false表示为不是季末
     */
    public static boolean isSeasonEnd(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        int y = calendar.get(Calendar.MONTH) + 1;
        int d = calendar.get(Calendar.DATE);
        if (y == 3 && d == 31) {
            return true;
        }
        if (y == 6 && d == 30) {
            return true;
        }
        if (y == 9 && d == 30) {
            return true;
        }
        if (y == 12 && d == 31) {
            return true;
        }
        return false;
    }
 
    /**
     * 判断某天是否为年末
     * 
     * @param date 日期对象
     * @return true表示为年末,false表示为不是年末
     */
    public static boolean isYearEnd(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        int y = calendar.get(Calendar.MONTH) + 1;
        int d = calendar.get(Calendar.DATE);
        if (y == 12 && d == 31) {
            return true;
        }
        return false;
    }
 
    /**
     * 获取耗时
     * 
     * @param newDate 新日期
     * @param startDate 开始日期
     * @return 耗时的毫秒数
     */
    public static Long getProcessedTime(Date newDate, Date startDate) {
        try {
            Long p = (newDate.getTime() - startDate.getTime());
            return p;
        } catch (Exception e) {
            return 0L;
        }
    }
 
    /**
     * 获取耗时
     * 
     * @param startDate 开始日期
     * @return 到当前时间的耗时的好描述
     */
    public static String getProcessedTime(Date startDate) {
        return getProcessedTime(new Date(), startDate) + "ms";
    }
 
    /**
     * 获取当前的年份
     * @return 年份
     */
    public static String getCurrentYear() {
        Calendar c = Calendar.getInstance();
        return String.valueOf(c.get(Calendar.YEAR) + 1900);
    }
 
    /**
     * 获取当年的年初
     * @return 日期字符串
     */
    public static String getCurrentYearStart() {
        return getCurrentYear() + "-01-01 00:00:00";
    }
 
    /**
     * 获取当年的年末
     * @return 日期字符串
     */
    public static String getCurrentYearEnd() {
        return getCurrentYear() + "-12-31 23:59:59";
    }
 
    /**
     * 获取当前所在的季度
     * @return 季度
     */
    public static String getCurrentQuarter() {
        String currentMouth = getCurrentMouth();
        int currentMouthInt = getInt(currentMouth);
        if (currentMouthInt > 0 && currentMouthInt <= 3) {
            return "1";
        }
        else if (currentMouthInt > 3 && currentMouthInt <= 6) {
            return "2";
        }
        else if (currentMouthInt > 6 && currentMouthInt <= 9) {
            return "3";
        }
        else {
            return "4";
        }
    }
 
    /**
     * 字符串转为数字
     * @param s 字符串
     * @return 数字
     */
    private static int getInt(String s){
        try{
            return Integer.valueOf(s);
        }catch (Exception e){
 
        }
        return 0;
    }
 
    /**
     * 获取当前季度的开始日期
     * @return 日期字符串
     */
    public static String getCurrentQuarterStart() {
        String currentQuarter = getCurrentQuarter();
        if ("1".equalsIgnoreCase(currentQuarter)) {
            return getCurrentYearStart();
        }
        else if ("2".equalsIgnoreCase(currentQuarter)) {
            return getCurrentYear() + "-04-01 00:00:00";
        }
        else if ("3".equalsIgnoreCase(currentQuarter)) {
            return getCurrentYear() + "-07-01 00:00:00";
        }
        else {
            return getCurrentYear() + "-10-01 00:00:00";
        }
    }
 
    /**
     * 获取当前季度的结束日期
     * @return 日期字符串
     */
    public static String getCurrentQuarterEnd() {
        String currentQuarter = getCurrentQuarter();
        if ("1".equalsIgnoreCase(currentQuarter)) {
            return getCurrentYear() + "-03-31 23:59:59";
        }
        else if ("2".equalsIgnoreCase(currentQuarter)) {
            return getCurrentYear() + "-06-30 23:59:59";
        }
        else if ("3".equalsIgnoreCase(currentQuarter)) {
            return getCurrentYear() + "-09-30 23:59:59";
        }
        else {
            return getCurrentYear() + "-12-31 23:59:59";
        }
    }
 
    /**
     * 获取当前的月份
     * @return 日期字符串
     */
    public static String getCurrentMouth() {
        Calendar cal = Calendar.getInstance();
        cal.setTime(getNow());
        int m = cal.get(Calendar.MONTH);
        if (m < 10) {
            return "0" + String.valueOf(m);
        }
        else {
            return String.valueOf(m);
        }
    }
 
    /**
     * 获取当前月份的开始时间
     * @return 日期格式字符串
     */
    public static String getCurrentMouthStart() {
        String currentMouth = getCurrentMouth();
        return getCurrentYear() + "-" + currentMouth + "-01 00:00:00";
    }
 
    /**
     * 获取当前月份的结束时间
     * @return 日期格式字符串
     */
    public static String getCurrentMouthEnd() {
        String currentMouth = getCurrentMouth();
        int currentMouthInt = getInt(currentMouth);
        if (currentMouthInt == 1 || currentMouthInt == 3
                || currentMouthInt == 5 || currentMouthInt == 7
                || currentMouthInt == 8 || currentMouthInt == 10
                || currentMouthInt == 12) {
            return getCurrentYear() + "-" + currentMouth + "-31 23:59:59";
        }
        else if (currentMouthInt == 2) {
            if (isLeapYear(getInt(getCurrentYear()))) {
                return getCurrentYear() + "-" + currentMouth + "-29 23:59:59";
            }else {
                return getCurrentYear() + "-" + currentMouth + "-28 23:59:59";
            }
        } else {
            return getCurrentYear() + "-" + currentMouth + "-30 23:59:59";
        }
    }
 
    /**
     * 是否是闰年
     * 
     * @param year 年份
     * @return true为闰年,false不是闰年
     */
    public static boolean isLeapYear(int year) {
        if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
            return true;
        }else {
            return false;
        }
    }
 
    /**
     * 获取当前日期
     * @return 当前日期的字符串
     */
    public static String getCurrentDay() {
        Calendar cal = Calendar.getInstance();
        cal.setTime(getNow());
        int day = cal.get(Calendar.DAY_OF_MONTH);
        if (day < 10) {
            return "0" + String.valueOf(day);
        }else {
            return String.valueOf(day);
        }
    }
 
    /**
     * 获取当天的开始时间
     * @return  日期字符串
     */
    public static String getCurrentDayStart() {
        return  LocalDateTime.of(LocalDateTime.now().toLocalDate(), LocalTime.MIN).format(DateTimeFormatter.ofPattern(DateTimeFormat));
    }
 
    /**
     * 获取当前的结束时间
     * @return 日期字符串
     */
    public static String getCurrentDayEnd() {
        return  LocalDateTime.of(LocalDateTime.now().toLocalDate(), LocalTime.MAX).format(DateTimeFormatter.ofPattern(DateTimeFormat));
    }
 
    /**
     * 获取某个时间段内的所有日期
     * @param dBegin 开始日期
     * @param dEnd 结束日期
     * @return 期间的所有日期
     */
    public static List<Date> getDateInRange(Date dBegin, Date dEnd) {
        List lDate = new ArrayList();
        lDate.add(dBegin);
        Calendar calBegin = Calendar.getInstance();
        // 使用给定的 Date 设置此 Calendar 的时间
        calBegin.setTime(dBegin);
        Calendar calEnd = Calendar.getInstance();
        // 使用给定的 Date 设置此 Calendar 的时间
        calEnd.setTime(dEnd);
        // 测试此日期是否在指定日期之后
        while (dEnd.after(calBegin.getTime())) {
            // 根据日历的规则,为给定的日历字段添加或减去指定的时间量
            calBegin.add(Calendar.DAY_OF_MONTH, 1);
            lDate.add(calBegin.getTime());
        }
        return lDate;
    }
 
    /**
     * 字符串转时间格式,主要是直接用hibernate查询SQL语句出来的内容使用
     * @param value 值
     * @return 移除了毫秒的后三位
     */
    public static Date getDateFromStringForVci(String value){
        Date d = null;
        if(StringUtils.isNotBlank(value)){
            try{
                if(value.indexOf("-") > -1 && value.indexOf(".")> -1 &&value.indexOf(" ") > -1 && value.substring(value.lastIndexOf(".") +1).length() >= 9){
                    //2013-4-19.14.5. 45. 734000000  这种格式,这个在使用SQL语句直接查询出时间字段的时候就会显示成这样
                    String ymd = value.substring(0,value.indexOf("."));
                    value = value.substring(value.indexOf(".") + 1);
                    if(value.indexOf(".")> -1){
                        String hms = value.substring(0,value.lastIndexOf("."));
                        String nano = value.substring(value.lastIndexOf(".") + 1).trim();
                        if(nano.length()>3){
                            nano = nano.substring(0,3);
                        }
                        hms = hms.replace(".", ":").replace(" ", "");
                        Date tempDate = VciDateUtil.str2Date(ymd + " " + hms , "yyyy-M-d h:m:s");
                        if(tempDate!=null){
                            d = VciDateUtil.str2Date(VciDateUtil.date2Str(tempDate, VciDateUtil.DateTimeFormat) + "." + nano, VciDateUtil.DateTimeMillFormat);
                        }
                    }
                } else if(VciBaseUtil.isNumber(value)){
                    d = new Date();
                    try{
                        d = VciDateUtil.str2Date(value, VciDateUtil.DateTimeMillFormatStr);
                    }catch(Exception e){
                        if(value.length() != 14){
                            d.setTime(VciBaseUtil.getLong(value));
                        }else {
                            try {
                                d = VciDateUtil.str2Date(value, VciDateUtil.DateTimeFormatStr);
                                Calendar cal = Calendar.getInstance();
                                cal.setTime(d);
                                if(cal.get(Calendar.YEAR) < 1900){
                                    d.setTime(VciBaseUtil.getLong(value));
                                }
                            } catch (Exception e2) {
                                //说明不是时间格式
                                d.setTime(VciBaseUtil.getLong(value));
                            }
                        }
                    }
                }else{
                    d = VciDateUtil.str2Date(value, VciDateUtil.DateTimeMillFormat);
                }
            }catch(Exception e){
                try{
                    d = VciDateUtil.str2Date(value, VciDateUtil.DateTimeMillFormat);
                }catch (Exception e1) {
 
                }
            }
        }
        return d;
    }
 
    /**
     * 读取文本到时间格式
     * @param text
     * @return
     */
    public static Date readText2Date(String text){
        if(VciBaseUtil.isNullOrNullString(text)) {
            return null;
        }
        SimpleDateFormat dateFormat = null;
        int exactDateLength = 0;
        if(text.trim().indexOf("/")>-1 && text.trim().length() ==19){
            exactDateLength = 19;
            dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        }
        else if(text.trim().indexOf("/")>-1 && text.trim().length() ==17){
            exactDateLength = 17;
            dateFormat = new SimpleDateFormat("yy/MM/dd HH:mm:ss");
        }
        else if(text.trim().indexOf("/")>-1 && text.trim().length() ==8){
            exactDateLength = 8;
            dateFormat = new SimpleDateFormat("yy/MM/dd");
        }
        else if(text.trim().indexOf("-")>-1 && text.trim().length() >=19){
            if(text.trim().length() == 19){
                exactDateLength = 19;
                dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            }else if(text.trim().length() == 23){
                exactDateLength = 23;
                dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
            }
        }
        else if (text.trim().indexOf("-")>-1 && text.trim().length() ==17){
            exactDateLength = 17;
            dateFormat = new SimpleDateFormat("yy-MM-dd HH:mm:ss");
        }
        else if(text.trim().indexOf("-")>-1 && text.trim().length() ==8){
            exactDateLength = 8;
            dateFormat = new SimpleDateFormat("yy-MM-dd");
        }//先弄这么多,不够再添加
        else{
            exactDateLength = 19;
            dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        }
        if ((text != null) && (exactDateLength >= 0)&& (text.length() != exactDateLength)) {
            throw new IllegalArgumentException("不能初始化时间,因为内容不到" + exactDateLength + "长度");
        }
        try {
            return VciDateUtil.str2Date(VciDateUtil.date2Str(dateFormat.parse(text), VciDateUtil.DateTimeFormat), VciDateUtil.DateTimeMillFormat);//无论界面是什么格式,我们都转化为"yyyy-MM-dd HH:mm:ss.SSS"这样可以统一后台的内容
        } catch (ParseException ex) {
            throw new IllegalArgumentException("不能格式化日期: "+ ex.getMessage(), ex);
        } catch (Exception e) {
            throw new IllegalArgumentException("不能格式化日期: "+ e.getMessage(), e);
        }
    }
 
    /**
     * 获取某天的农历形式
     *
     * @param d
     * @return
     * @throws Exception
     */
    public static String getChinaDate(String d) throws Exception {
        Date s = str2Date(d, DateFormat);
        SimpleDateFormat chineseDateFormat = new SimpleDateFormat("yyyy年MM月dd日");
        Calendar today = Calendar.getInstance();
        try {
            today.setTime(chineseDateFormat.parse(date2Str(s,
                    "yyyy年MM月dd日")));
        } catch (ParseException e) {
            throw new Exception(e);
        }
        Lunar lunar = new Lunar(today);
        return lunar.getDate();
    }
 
    /**
     * 获取时间的time值
     * @param date date
     * @Return java.lang.Long
     */
    public static Long getTime(Date date) {
        if(date == null){
            return null;
        }
        return date.getTime();
    }
 
    /**
     * 获取当前时间的time值
     * @Return java.lang.Long
     */
    public static Long getNowTime() {
        Date date = new Date();
        return date.getTime();
    }
 
    /**
     * 将timestamp转换为Date
     * @param timestamp timestamp
     * @Return java.util.Date
     */
    public static Date long2Date(Long timestamp){
        if(timestamp == null){
            return null;
        }
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(timestamp);
        return calendar.getTime();
    }
}