Pu Zhibing
6 天以前 4c99ee7028c3fe58a2cd4b8273b22c75c45574fc
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
package com.stylefeng.guns.modular.system.util;
 
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils;
 
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.TimeZone;
 
/**
 * <h3>处理时间的工具类</h3>
 */
public class DateUtil {
 
    
    
    
    private static TimeZone tz = TimeZone.getTimeZone("GMT+0");
 
    // private static TimeZone tz = TimeZone.getTimeZone("Asia/Shanghai");
 
    /**
     * 格式化日期
     */
    public static Date parse(String date, String pattern) {
        try {
            return DateUtils.parseDate(date, pattern);
        } catch (ParseException e) {
            e.printStackTrace();
            return null;
        }
    }
 
    /**
     * 格式化日期
     */
    public static Date parseDate(String date) {
        return parse(date, "yyyy-MM-dd");
    }
 
    /**
     * 格式化日期
     */
    public static String format(Date date, String pattern) {
        return DateFormatUtils.format(date, pattern);
    }
 
    public static boolean hourMinuteBetween(String nowDate, String startDate, String endDate) throws Exception{
        
        SimpleDateFormat format = new SimpleDateFormat("HH:mm");
        
        Date now = format.parse(nowDate);
        Date start = format.parse(startDate);
        Date end = format.parse(endDate);
        
        long nowTime = now.getTime();
        long startTime = start.getTime();
        long endTime = end.getTime();
        
        return nowTime >= startTime && nowTime <= endTime;
    }
 
    /**
     * 得到系统日期
     * 
     * @return
     */
    public static Date getDate() {
        TimeZone.setDefault(tz);
        return new Date();
    }
 
    /**
     * 获取当然凌晨的时间
     * 
     * @return Date
     */
    public static Date getZero() {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        return calendar.getTime();
    }
 
    /**
     * 判断日期是否在from,to之内 "yyyy-MM-dd" 格式
     * 
     * @param time
     *            指定日期
     * @param from
     *            开始日期
     * @param to
     *            结束日期
     * @return true 在之间 false 不在之间
     */
    public static boolean belongCalendar(Date time, Date from, Date to) {
        Calendar date = Calendar.getInstance();
        date.setTime(time);
 
        Calendar after = Calendar.getInstance();
        after.setTime(from);
 
        Calendar before = Calendar.getInstance();
        before.setTime(to);
 
        if ((date.after(after) && date.before(before)) || (time.compareTo(from) == 0 || time.compareTo(to) == 0)) {
            return true;
        } else {
            return false;
        }
    }
 
    /**
     * 两个时间之差
     * 
     * @param startTime
     * @param endTime
     * @param format
     * @return
     * @throws ParseException
     */
    public static String dateDiff(String startTime, String endTime, String format) throws ParseException {
        // 按照传入的格式生成一个simpledateformate对象
        SimpleDateFormat sd = new SimpleDateFormat(format);
        long nd = 1000 * 24 * 60 * 60;// 一天的毫秒数
        long nh = 1000 * 60 * 60;// 一小时的毫秒数
        long nm = 1000 * 60;// 一分钟的毫秒数
        long ns = 1000;// 一秒钟的毫秒数
        long diff;
        long day = 0;
        long hour = 0;
        long min = 0;
        long sec = 0;
        // long time=0;
        String strTime = "";
        // 获得两个时间的毫秒时间差异
        diff = sd.parse(endTime).getTime() - sd.parse(startTime).getTime();
        day = diff / nd;// 计算差多少天
        hour = diff % nd / nh + day * 24;// 计算差多少小时
        min = diff % nd % nh / nm + day * 24 * 60;// 计算差多少分钟
        sec = diff % nd % nh % nm / ns;// 计算差多少秒
        // 输出结果
        /*
         * System.out.println("时间相差:" + day + "天" + (hour - day * 24) + "小时" +
         * (min - day * 24 * 60) + "分钟" + sec + "秒。");
         * System.out.println("hour=" + hour + ",min=" + min);
         */
        if (day == 1) {
            strTime = "昨天";
        } else if (day > 1) {
            // strTime=day+"天前";
            strTime = startTime.substring(0, 10);
        } else if (hour >= 1 && hour < 24) {
            strTime = hour + "小时前";
        } else {
            if (min == 0) {
                strTime = sec + "秒钟前";
            } else {
                strTime = min + "分钟前";
            }
 
        }
        // if (str.equalsIgnoreCase("h")) {
        // return hour;
        // } else {
        // return min;
        // }
 
        // if (str.equalsIgnoreCase("h")) {
        // return hour;
        // } else {
        // return min;
        // }
        return strTime;
    }
 
    /**
     * 得到系统Calendar日期
     * 
     * @return
     */
    public static Calendar getCalendar() {
        TimeZone.setDefault(tz);
        Calendar cal = Calendar.getInstance();
        return cal;
    }
 
    /**
     * 获取当前时间
     * 
     * @return
     */
    public static long getMillisecond() {
        long millisecond = 0;
        TimeZone.setDefault(tz);
        Calendar cal = Calendar.getInstance();
        millisecond = cal.getTimeInMillis();
        return millisecond;
    }
 
    /**
     * 获取本月1号的时间戳
     * 
     * @return
     */
    public static long getMillisecond_MONTH() {
        long millisecond = 0;
        TimeZone.setDefault(tz);
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.DAY_OF_MONTH, 1);
        millisecond = cal.getTimeInMillis();
        return millisecond;
    }
 
    
    /**
     * 获取上个月1号的时间戳
     * 
     * @return
     */
    public static long getMillisecond_FRONTMONTH() {
        long millisecond = 0;
        Calendar cal = getCalendar();
        cal.set(Calendar.DAY_OF_MONTH, 1);
        cal.set(Calendar.MONTH, Calendar.MONTH - 2);
        millisecond = cal.getTimeInMillis();
        return millisecond;
    }
 
    /**
     * 获取当前毫秒数
     * 
     * @return long
     */
    public static long getCurMilli() {
        long millisecond = 0;
        Calendar cal = Calendar.getInstance();
        millisecond = cal.getTimeInMillis();
        return millisecond;
    }
 
    /**
     * 日期转毫秒
     * 
     * @param date
     * @return
     */
    public static long getMillisecond(Date date) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String newDate = "";
        if (!"".equals(date)) {
            newDate = sdf.format(date);
        } else {
            newDate = sdf.format(DateUtil.getDate());
        }
        long millisecond = 0;
        try {
            millisecond = sdf.parse(newDate).getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return millisecond;
    }
 
    /**
     * 日期转毫秒(加24小时,yyyy-MM-dd HH:mm:ss)
     * 
     * @param date
     * @return
     */
    public static long getMillisecond_24h(Date date) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String newDate = "";
        if (!"".equals(date)) {
            newDate = sdf.format(date);
        } else {
            newDate = sdf.format(DateUtil.getDate());
        }
        long millisecond = 24 * 3600 * 1000;
        try {
            millisecond += sdf.parse(newDate).getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return millisecond;
    }
 
    /**
     * 日期转毫秒(加N年)
     * 
     * @param date
     * @return
     */
    public static long getMillisecond_year(String date, Integer year) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String newDate = "";
        if ("".equals(date)) {
            newDate = sdf.format(DateUtil.getDate());
        } else {
            newDate = getDateTime(Long.parseLong(date));
        }
        Date dt = null;
        try {
            dt = sdf.parse(newDate);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        Calendar rightNow = Calendar.getInstance();
        rightNow.setTime(dt);
        rightNow.add(Calendar.YEAR, year);
        Date dt1 = rightNow.getTime();
        return dt1.getTime();
    }
 
    /**
     * 日期转毫秒(加N天)
     * 
     * @param date
     *            毫秒字符串
     * @return
     */
    public static Date getMillisecond_day(String date, Integer day) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String newDate = "";
        if ("".equals(date)) {
            newDate = sdf.format(DateUtil.getDate());
        } else {
            newDate = date;
        }
        Date dt = null;
        try {
            dt = sdf.parse(newDate);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        Calendar rightNow = Calendar.getInstance();
        rightNow.setTime(dt);
        rightNow.add(Calendar.DATE, day);
        Date dt1 = rightNow.getTime();
        Date dates = new Date(dt1.getTime());
        return dates;
    }
 
    /**
     * 日期转毫秒(加N月)
     * 
     * @param date
     * @return
     */
    public static long getMillisecond_month(String date, Integer day) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String newDate = "";
        if ("".equals(date)) {
            newDate = sdf.format(DateUtil.getDate());
        } else {
            newDate = getDateTime(Long.parseLong(date));
        }
        Date dt = null;
        try {
            dt = sdf.parse(newDate);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        Calendar rightNow = Calendar.getInstance();
        rightNow.setTime(dt);
        rightNow.add(Calendar.MONTH, day);
        Date dt1 = rightNow.getTime();
        return dt1.getTime();
    }
    
    /**
     * 日期转毫秒(加分钟)
     * 
     * @param date
     * @return
     */
    public static long getMillisecond_fz(String date, Integer day) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String newDate = "";
        if ("".equals(date)) {
            newDate = sdf.format(DateUtil.getDate());
        } else {
            newDate = getDateTime(Long.parseLong(date));
        }
        Date dt = null;
        try {
            dt = sdf.parse(newDate);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        Calendar rightNow = Calendar.getInstance();
        rightNow.setTime(dt);
        rightNow.add(Calendar.MINUTE, day);
        Date dt1 = rightNow.getTime();
        return dt1.getTime();
    }
    
    public static Date getMillisecond_fz1(String date, Integer day) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date dt = null;
        try {
            dt = sdf.parse(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        Calendar rightNow = Calendar.getInstance();
        rightNow.setTime(dt);
        rightNow.add(Calendar.MINUTE, day);
        Date dt1 = rightNow.getTime();
        return dt1;
    }
 
    /**
     * 字符串日期转毫秒
     * 
     * @param date
     * @return
     */
    public static long getMillisecond_str(String date) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        if ("".equals(date)) {
            date = sdf.format(DateUtil.getDate());
        }
        long millisecond = 0;
        try {
            millisecond = sdf.parse(date).getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return millisecond;
    }
 
    /**
     * 字符串日期转毫秒
     * 
     * @param date
     * @return
     */
    public static long getMillisecond_strYmd(String date) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        if ("".equals(date)) {
            date = sdf.format(DateUtil.getDate());
        }
        long millisecond = 0;
        try {
            millisecond = sdf.parse(date).getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return millisecond;
    }
 
    /**
     * 字符串日期转Date
     * 
     * @param string
     * @return date
     * @throws ParseException
     */
    public static Date getStrToDate(String dateString) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date date = sdf.parse(dateString);
        return date;
    }
 
    /**
     * 字符串日期转Date
     * 
     * @param date
     * @return
     */
    public static Date getDate_str(String dateStr) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        sdf.setTimeZone(tz);
        if ("".equals(dateStr)) {
            dateStr = sdf.format(DateUtil.getDate());
        }
        Date date = null;
        try {
            date = sdf.parse(dateStr);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }
 
    /**
     * 字符串日期转Date yyyy-MM-dd HH:mm
     * 
     * @param date
     * @return
     */
    public static Date getDate_str2(String dateStr) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        sdf.setTimeZone(tz);
        if ("".equals(dateStr)) {
            dateStr = sdf.format(DateUtil.getDate());
        }
        Date date = null;
        try {
            date = sdf.parse(dateStr);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }
 
    /**
     * 字符串日期转Date yyyy-MM-dd HH:mm:ss
     * 
     * @param date
     * @return
     */
    public static Date getDate_str3(String dateStr) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        sdf.setTimeZone(tz);
        if ("".equals(dateStr)) {
            dateStr = sdf.format(DateUtil.getDate());
        }
        Date date = null;
        try {
            date = sdf.parse(dateStr);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }
 
    /**
     * 字符串日期转Date
     * 
     * @param date
     * @return
     */
    public static Date getDate_strYMd(Long dateStr) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        if (dateStr == null) {
            dateStr = DateUtil.getCurMilli();
        }
        Date date = null;
        try {
            date = sdf.parse(sdf.format(new Date(dateStr)));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }
 
    /**
     * 毫秒转Date
     * 
     * @param date
     * @return
     */
    public static Date getDate_strYMdHms(Long dateStr) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        if (dateStr == null) {
            dateStr = DateUtil.getCurMilli();
        }
        Date date = null;
        try {
            date = sdf.parse(sdf.format(new Date(dateStr)));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }
 
    /**
     * 字符串日期转Date
     * 
     * @param date
     * @return
     */
    public static Date getDate_strYMdHm(Long dateStr) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        if (dateStr == null) {
            dateStr = DateUtil.getCurMilli();
        }
        Date date = null;
        try {
            date = sdf.parse(sdf.format(new Date(dateStr)));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }
 
    /**
     * 字符串日期转毫秒
     * 
     * @param date
     * @return
     */
    public static long getMillisecond_strDmy(String date) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        if ("".equals(date)) {
            date = sdf.format(DateUtil.getDate());
        }
        long millisecond = 0;
        try {
            millisecond = sdf.parse(date).getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return millisecond;
    }
 
    /**
     * 字符串日期转毫秒转毫秒(加24小时)
     * 
     * @param date
     * @return
     */
    public static long getMillisecond_str_24h(String date) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        if ("".equals(date)) {
            date = sdf.format(DateUtil.getDate());
        }
        long millisecond = 24 * 3600 * 1000;
        try {
            millisecond += sdf.parse(date).getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return millisecond;
    }
 
    /**
     * 字符串日期转毫秒转毫秒(加24小时)
     * 
     * @param date
     * @return
     */
    public static long getMillisecond_strYmd_24h(String date) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        if ("".equals(date)) {
            date = sdf.format(DateUtil.getDate());
        }
        long millisecond = 24 * 3600 * 1000;
        try {
            millisecond += sdf.parse(date).getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return millisecond;
    }
 
    /**
     * 毫秒转日期
     * 
     * @param millisecond
     * @return
     */
    public static String getDate(long millisecond) {
        if (millisecond == 0) {
            millisecond = getCurMilli();
        }
        SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar = getCalendar();
        calendar.setTimeInMillis(millisecond);
        return dateformat.format(calendar.getTime());
    }
 
    /**
     * 转换为指定格式的时间
     * 
     * @return Date
     */
    public static Date getDate(String date, String pattern) {
        SimpleDateFormat format = new SimpleDateFormat(pattern);
        Date d = null;
        try {
            d = format.parse(date);
        } catch (ParseException ex) {
            return null;
        }
        return d;
    }
 
    /**
     * 毫秒转日期
     * 
     * @param millisecond
     * @return
     */
    public static String getDate_HH(long millisecond) {
        if (millisecond == 0) {
            millisecond = getCurMilli();
        }
        SimpleDateFormat dateformat = new SimpleDateFormat("HH");
        Calendar calendar = getCalendar();
        calendar.setTimeInMillis(millisecond);
        return dateformat.format(calendar.getTime());
    }
 
    /**
     * 毫秒转日期时间
     * 
     * @param millisecond
     * @return
     */
    public static String getDateTime(long millisecond) {
        if (millisecond == 0) {
            millisecond = getCurMilli();
        }
        SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Calendar calendar = getCalendar();
        calendar.setTimeInMillis(millisecond);
        return dateformat.format(calendar.getTime());
    }
 
    /**
     * 毫秒转年月日
     * 
     * @param millisecond
     * @return
     */
    public static String getDateYMD(long millisecond) {
        if (millisecond == 0) {
            millisecond = getCurMilli();
        }
        SimpleDateFormat dateformat = new SimpleDateFormat("yyyy年MM月dd日");
        Calendar calendar = getCalendar();
        calendar.setTimeInMillis(millisecond);
        return dateformat.format(calendar.getTime());
    }
 
    /**
     * 两日期相差毫秒
     * 
     * @param startDate
     * @param endDate
     * @return
     */
    public static long getMinusMillisecond(Date startDate, Date endDate) {
        long startMillisecond = getMillisecond(startDate);
        long endMillisecond = getMillisecond(endDate);
        long minusMillisecond = endMillisecond - startMillisecond;
        if (minusMillisecond < 0) {
            minusMillisecond = 0;
        }
        return minusMillisecond;
    }
 
    /**
     * 两日期相差天数
     * 
     * @param startDate
     * @param endDate
     * @return
     */
    public static long getMinusDay(Date startDate, Date endDate) {
        long startMillisecond = getMillisecond(startDate);
        long endMillisecond = getMillisecond(endDate);
        long minusMillisecond = endMillisecond - startMillisecond;
        long day = 0;
        if (minusMillisecond < 0) {
            day = 0;
        } else {
            day = minusMillisecond / (24 * 3600 * 1000);
        }
        return day;
    }
 
    /**
     * 前N天毫秒
     * 
     * @param day
     * @return
     */
    public static long getRetreatDay_millisecond(int day) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        long nowMillisecond = 0;
        try {
            nowMillisecond = sdf.parse(sdf.format(DateUtil.getDate())).getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        nowMillisecond += 24 * 3600 * 1000;
        long retreatMillisecond = 24 * 3600 * 1000 * day;
        return nowMillisecond - retreatMillisecond;
    }
 
    /**
     * 前N天时间
     * 
     * @param day
     * @return
     */
    public static String getRetreatDay_millisecond1(int day) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        long nowMillisecond = 0;
        try {
            nowMillisecond = sdf.parse(sdf.format(DateUtil.getDate())).getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        nowMillisecond += 24 * 3600 * 1000;
        long retreatMillisecond = 24 * 3600 * 1000 * day;
        long s = nowMillisecond - retreatMillisecond;
        Date date = new Date(s);
        String res = sdf.format(date);
        return res;
    }
 
    // 当前时间前30天
    public static String getRetreatDay_millisecond2() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date today = new Date();
        String endDate = sdf.format(today);// 当前日期
        // 获取三十天前日期
        Calendar theCa = Calendar.getInstance();
        theCa.setTime(today);
        theCa.add(theCa.DATE, -30);// 最后一个数字30可改,30天的意思
        Date start = theCa.getTime();
        String startDate = sdf.format(start);// 三十天之前日期
        return startDate;
    }
 
    /**
     * 日期转秒
     * 
     * @param date
     * @return
     */
    public static long getDecond(Date date) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String newDate = "";
        if (!"".equals(date)) {
            newDate = sdf.format(date);
        } else {
            newDate = sdf.format(DateUtil.getDate());
        }
        long second = 0;
        try {
            second = sdf.parse(newDate).getTime() / 1000;
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return second;
    }
 
    /**
     * 日期转String
     * 
     * @param date
     * @return
     * @throws ParseException
     */
    public static String getDateToString(Date date,String pattern) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        String newDate = sdf.format(date);
        long millisecond = sdf.parse(newDate).getTime();
        Calendar calendar = getCalendar();
        calendar.setTimeInMillis(millisecond);
        return sdf.format(calendar.getTime());
    }
 
 
    /**
     * 毫秒转星期XX
     * 
     * @param millisecond
     * @return
     */
    public static int getDate_week(Long millisecond) {
        if (millisecond == null) {
            millisecond = getCurMilli();
        }
        Calendar cal = getCalendar();
        cal.setTimeInMillis(millisecond);
        return cal.get(Calendar.DAY_OF_WEEK) - 1;
 
    }
 
    /**
     * 获取当前系统时间已yyyy-MM-dd HH:mm:ss格式化的字符串
     */
    public static String nowStr() {
 
        SimpleDateFormat dateFormat = new SimpleDateFormat("yy-MM-dd HH:mm:ss");
        return dateFormat.format(getDate());
    }
 
    /**
     * 
     * 获取之前几天日期
     * 
     * @param pattern
     *            yyyy-MM-dd(默认)
     * @param few
     *            之前几天
     */
    public static String beforeFewDayStr(String pattern, Integer few) {
 
        if (pattern == null || "".equals(pattern)) {
            pattern = "yyyy-MM-dd";
        }
        Calendar c = getCalendar();
        c.add(Calendar.DATE, -few);
        return new SimpleDateFormat(pattern).format(c.getTime());
    }
    
    
    /**
     * 得到几天后的时间
     *
     * @param d
     * @param day
     * @return
     */
    public static Date getDateAfter(Date d, int day) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Calendar now = Calendar.getInstance();
        now.setTime(d);
        now.set(Calendar.DATE, now.get(Calendar.DATE) - day);//+后 -前
        return now.getTime();
    }
    
 
    /**
     * 获取今天日期
     * 
     * @param pattern
     *            yyyy-MM-dd(默认)
     */
    public static String todayStr(String pattern) {
 
        if (pattern == null || "".equals(pattern)) {
            pattern = "yyyy-MM-dd";
        }
        return new SimpleDateFormat(pattern).format(getDate());
    }
 
    /**
     * 获取当前系统时间戳字符串
     */
    public static String nowDateLongStr() {
 
        return getDate().getTime() + "";
    }
 
    /**
     * 获取当前系统时间
     * 
     * @return
     */
    public static Date now() {
 
        return getDate();
    }
 
    /*public static void main(String[] args) throws ParseException {
        // 打印测试日期包含
        Date time1 = getDate_str("2017-3-11");
        Date time2 = getDate_str("2017-3-15");
        Date time3 = getDate_str("2017-3-17");
        Date time4 = getDate_str("2017-3-12");
        Date time5 = getDate_str("2017-3-16");
        Date from = getDate_str("2017-3-12");
        Date to = getDate_str("2017-3-16");
        System.out.println(belongCalendar(time1, from, to));
        System.out.println(belongCalendar(time2, from, to));
        System.out.println(belongCalendar(time3, from, to));
        System.out.println(belongCalendar(time4, from, to));
        System.out.println(belongCalendar(time5, from, to));
        System.out.println(nowStr());
 
    }
*/
    /**
     * 把日期往后增加一天. 正数往后推,负数往前移动
     * 
     * @param day
     * @return
     */
    public static String getString(int day) {
        Date date = new Date();// 取时间
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(date);
        calendar.add(calendar.DATE, day);// 把日期往后增加一天.整数往后推,负数往前移动
        date = calendar.getTime(); // 这个时间就是日期往后推一天的结果
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        String dateString = formatter.format(date);
        return dateString;
    }
 
    /**
     * 根据当前日期获得所在周的日期区间(周一和周日日期)
     * 
     * @return
     * @author zhaoxuepu
     * @throws ParseException
     */
    public static String getTimeInterval(Date date) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        // 判断要计算的日期是否是周日,如果是则减一天计算周六的,否则会出问题,计算到下一周去了
        int dayWeek = cal.get(Calendar.DAY_OF_WEEK);// 获得当前日期是一个星期的第几天
        if (1 == dayWeek) {
            cal.add(Calendar.DAY_OF_MONTH, -1);
        }
        // System.out.println("要计算日期为:" + sdf.format(cal.getTime())); // 输出要计算日期
        // 设置一个星期的第一天,按中国的习惯一个星期的第一天是星期一
        cal.setFirstDayOfWeek(Calendar.MONDAY);
        // 获得当前日期是一个星期的第几天
        int day = cal.get(Calendar.DAY_OF_WEEK);
        // 根据日历的规则,给当前日期减去星期几与一个星期第一天的差值
        cal.add(Calendar.DATE, cal.getFirstDayOfWeek() - day);
        String imptimeBegin = sdf.format(cal.getTime());
        // System.out.println("所在周星期一的日期:" + imptimeBegin);
        cal.add(Calendar.DATE, 6);
        String imptimeEnd = sdf.format(cal.getTime());
        // System.out.println("所在周星期日的日期:" + imptimeEnd);
        return imptimeBegin + "," + imptimeEnd;
    }
 
    /**
     * 根据当前日期获得上周的日期区间(上周周一和周日日期)
     * 
     * @return
     * @author zhaoxuepu
     */
    public static String getLastTimeInterval() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar1 = Calendar.getInstance();
        Calendar calendar2 = Calendar.getInstance();
        int dayOfWeek = calendar1.get(Calendar.DAY_OF_WEEK) - 1;
        int offset1 = 1 - dayOfWeek;
        int offset2 = 7 - dayOfWeek;
        calendar1.add(Calendar.DATE, offset1 - 7);
        calendar2.add(Calendar.DATE, offset2 - 7);
        // System.out.println(sdf.format(calendar1.getTime()));// last Monday
        String lastBeginDate = sdf.format(calendar1.getTime());
        // System.out.println(sdf.format(calendar2.getTime()));// last Sunday
        String lastEndDate = sdf.format(calendar2.getTime());
        return lastBeginDate + "," + lastEndDate;
    }
 
    public static String DateYUE() {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Calendar c = Calendar.getInstance();
        c.add(Calendar.MONTH, 0);
        c.set(Calendar.DAY_OF_MONTH, 1);// 设置为1号,当前日期既为本月第一天
        String first = format.format(c.getTime());
 
        // 获取当前月最后一天
        Calendar ca = Calendar.getInstance();
        ca.set(Calendar.DAY_OF_MONTH, ca.getActualMaximum(Calendar.DAY_OF_MONTH));
        String last = format.format(ca.getTime());
        return first + "," + last;
    }
 
    public static String getBeforeFirstMonthdate() {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar = Calendar.getInstance();
        Calendar calendar1 = Calendar.getInstance();
        calendar.add(Calendar.MONTH, -1);
        calendar.set(Calendar.DAY_OF_MONTH, 1);
 
        int month = calendar1.get(Calendar.MONTH);
        calendar1.set(Calendar.MONTH, month - 1);
        calendar1.set(Calendar.DAY_OF_MONTH, calendar1.getActualMaximum(Calendar.DAY_OF_MONTH));
        String str = format.format(calendar.getTime());
        String str1 = format.format(calendar1.getTime());
 
        return str + "," + str1;
    }
 
    /**
     * 获取某年第一天和最后一天日期
     * 
     * @param year
     *            年份
     * @return Date
     */
 
    public static String getYearFirst(int year) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar = Calendar.getInstance();
        calendar.clear();
        calendar.set(Calendar.YEAR, year);
 
        Calendar calendar1 = Calendar.getInstance();
        calendar1.clear();
        calendar1.set(Calendar.YEAR, year);
        calendar1.roll(Calendar.DAY_OF_YEAR, -1);
 
        String str = format.format(calendar.getTime());
        String str1 = format.format(calendar1.getTime());
 
        return str + "," + str1;
    }
 
    /**
     * 在指定日期上增加N天
     */
    public static Date addDate(Date date,long day) throws ParseException {
         long time = date.getTime(); // 得到指定日期的毫秒数
         day = day*24*60*60*1000; // 要加上的天数转换成毫秒数
         time+=day; // 相加得到新的毫秒数
         return new Date(time); // 将毫秒数转换成日期
    }
 
    
    // 获取一天开始和结束
    public static String getDay() {
        Date dBefore = new Date();
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd"); //设置时间格式
        String defaultStartDate = sdf.format(dBefore); //格式化前一天
        defaultStartDate = defaultStartDate+" 00:00:00";
        String defaultEndDate = defaultStartDate.substring(0,10)+" 23:59:59";
 
        return defaultStartDate + "," + defaultEndDate;
    }
 
 
 
 
    /**
     * 多语言时间日期格式转换
     * @param language  语言编号
     * @param datetime      标准格式化时间 yyyy-MM-dd
     * @return
     */
    public static String conversionFormat(Integer language, String datetime){
        String time = "";
        String date = datetime;
        int index = datetime.indexOf(" ");
        if(index != -1){
            time = datetime.substring(datetime.indexOf(" ") + 1);
            date = datetime.substring(0, datetime.indexOf(" "));
        }
        String[] split = date.split("-");
        switch (language){
            case 2:
                split[1] = englishMonth(Integer.valueOf(split[1]));
                datetime = split[1] + " " + split[2] + ", " + split[0];
                if(index != -1){
                    datetime += " " + time;
                }
                break;
            case 3:
                split[1] = frenchMonth(Integer.valueOf(split[1]));
                datetime = split[2] + " " + split[1] + " " + split[0];
                if(index != -1){
                    datetime += " " + time;
                }
                break;
        }
        return datetime;
    }
 
 
    public static String conversionFormat1(Integer language, String datetime){
        String time = "";
        String date = datetime;
        int index = datetime.indexOf(" ");
        if(index != -1){
            time = datetime.substring(datetime.indexOf(" ") + 1);
            date = datetime.substring(0, datetime.indexOf(" "));
        }
        String[] split = date.split("-");
        switch (language){
            case 2:
                split[1] = englishMonth(Integer.valueOf(split[0]));
                datetime = split[0] + " " + split[1];
                if(index != -1){
                    datetime += " " + time;
                }
                break;
            case 3:
                split[1] = frenchMonth(Integer.valueOf(split[0]));
                datetime = split[1] + " " + split[0];
                if(index != -1){
                    datetime += " " + time;
                }
                break;
        }
        return datetime;
    }
 
 
 
    public static String frenchMonth(Integer month){
        String m = "";
        switch (month){
            case 1:
                m = "Janvier";
                break;
            case 2:
                m = "Février";
                break;
            case 3:
                m = "Mars";
                break;
            case 4:
                m = "Avril";
                break;
            case 5:
                m = "Mai";
                break;
            case 6:
                m = "Juin";
                break;
            case 7:
                m = "Juillet";
                break;
            case 8:
                m = "Août";
                break;
            case 9:
                m = "Septembre";
                break;
            case 10:
                m = "Octobre";
                break;
            case 11:
                m = "Novembre";
                break;
            case 12:
                m = "Décembre";
                break;
            default:
                m = "";
                break;
        }
        return m;
    }
 
 
 
    public static String englishMonth(Integer month){
        String m = "";
        switch (month){
            case 1:
                m = "January";
                break;
            case 2:
                m = "February";
                break;
            case 3:
                m = "March";
                break;
            case 4:
                m = "April";
                break;
            case 5:
                m = "May";
                break;
            case 6:
                m = "June";
                break;
            case 7:
                m = "July";
                break;
            case 8:
                m = "August";
                break;
            case 9:
                m = "September";
                break;
            case 10:
                m = "October";
                break;
            case 11:
                m = "November";
                break;
            case 12:
                m = "December";
                break;
            default:
                m = "";
                break;
        }
        return m;
    }
 
 
    
    
    public static void main(String[] args) throws ParseException {
        System.out.println(getDay());
    }
 
}