|
@@ -482,29 +482,80 @@ public class DateUtil {
|
482
|
482
|
|
483
|
483
|
/**
|
484
|
484
|
* 获取当前时间
|
|
485
|
+ *
|
485
|
486
|
* @return
|
486
|
487
|
* @throws ParseException
|
487
|
488
|
*/
|
488
|
|
- public static Date getTime()throws ParseException{
|
|
489
|
+ public static Date getTime() throws ParseException {
|
489
|
490
|
Date time = Calendar.getInstance().getTime();
|
490
|
|
- SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
|
491
|
+ SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
491
|
492
|
String format = dateFormat.format(time);
|
492
|
493
|
Date date = dateFormat.parse(format);
|
493
|
|
- return date;
|
|
494
|
+ return date;
|
|
495
|
+ }
|
|
496
|
+
|
|
497
|
+ /**
|
|
498
|
+ * 获取当前时间年月
|
|
499
|
+ *
|
|
500
|
+ * @return
|
|
501
|
+ * @throws ParseException
|
|
502
|
+ */
|
|
503
|
+ public static Date getSpecificTime() {
|
|
504
|
+ Date date = null;
|
|
505
|
+ try {
|
|
506
|
+ Date time = Calendar.getInstance().getTime();
|
|
507
|
+ SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM");
|
|
508
|
+ String format = dateFormat.format(time);
|
|
509
|
+ date = dateFormat.parse(format);
|
|
510
|
+ } catch (ParseException e) {
|
|
511
|
+ e.printStackTrace();
|
|
512
|
+ }
|
|
513
|
+ return date;
|
|
514
|
+ }
|
|
515
|
+
|
|
516
|
+ /**
|
|
517
|
+ * 获取当前时间年月日
|
|
518
|
+ *
|
|
519
|
+ * @return
|
|
520
|
+ * @throws ParseException
|
|
521
|
+ */
|
|
522
|
+ public static Date getDayTime() {
|
|
523
|
+ Date date = null;
|
|
524
|
+ try {
|
|
525
|
+ Date time = Calendar.getInstance().getTime();
|
|
526
|
+ SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
527
|
+ String format = dateFormat.format(time);
|
|
528
|
+ date = dateFormat.parse(format);
|
|
529
|
+ } catch (ParseException e) {
|
|
530
|
+ e.printStackTrace();
|
|
531
|
+ }
|
|
532
|
+ return date;
|
494
|
533
|
}
|
495
|
534
|
|
496
|
535
|
/**
|
497
|
536
|
* 获取上一个月的日期
|
|
537
|
+ *
|
498
|
538
|
* @return
|
499
|
539
|
* @throws ParseException
|
500
|
540
|
*/
|
501
|
|
- public static String getLastMonth(){
|
|
541
|
+ public static String getLastMonth() {
|
502
|
542
|
Calendar c = Calendar.getInstance();
|
503
|
|
- SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd");
|
|
543
|
+ SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
504
|
544
|
c.setTime(new Date());
|
505
|
545
|
c.add(Calendar.MONTH, -1);
|
506
|
546
|
Date m = c.getTime();
|
507
|
547
|
String mon = dateFormat.format(m);
|
508
|
|
- return mon;
|
|
548
|
+ return mon;
|
|
549
|
+ }
|
|
550
|
+
|
|
551
|
+ /**
|
|
552
|
+ * 获取当月的 天数
|
|
553
|
+ */
|
|
554
|
+ public static int getCurrentMonthDay() {
|
|
555
|
+ Calendar a = Calendar.getInstance();
|
|
556
|
+ a.set(Calendar.DATE, 1);
|
|
557
|
+ a.roll(Calendar.DATE, -1);
|
|
558
|
+ int maxDate = a.get(Calendar.DATE);
|
|
559
|
+ return maxDate;
|
509
|
560
|
}
|
510
|
561
|
}
|