1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package com.isenshi.util;
17
18 import java.util.Calendar;
19 import java.util.Date;
20 import java.util.GregorianCalendar;
21
22 public class CalendarUtils {
23
24 public static int getTodayYear(){
25 return Calendar.getInstance().get(Calendar.YEAR);
26 }
27
28 public static int getTodayMonth(){
29 return Calendar.getInstance().get(Calendar.MONTH) + 1;
30 }
31
32 public static int getTodayDate(){
33 return Calendar.getInstance().get(Calendar.DATE);
34 }
35
36 public static int getTodayYear(Date date){
37 if(date == null){
38 return getTodayYear();
39 }
40 Calendar cal = Calendar.getInstance();
41 cal.setTime(date);
42 return cal.get(Calendar.YEAR);
43 }
44
45 public static int getTodayMonth(Date date){
46 if(date == null){
47 return getTodayMonth();
48 }
49 Calendar cal = Calendar.getInstance();
50 cal.setTime(date);
51 return cal.get(Calendar.MONTH) + 1;
52 }
53
54 public static int getTodayDate(Date date){
55 if(date == null){
56 return getTodayDate();
57 }
58 Calendar cal = Calendar.getInstance();
59 cal.setTime(date);
60 return cal.get(Calendar.DATE);
61 }
62
63 public static Calendar getToday(){
64 Calendar cal = Calendar.getInstance();
65 int year = cal.get(Calendar.YEAR);
66 int month = cal.get(Calendar.MONTH);
67 int date = cal.get(Calendar.DATE);
68 return new GregorianCalendar(year, month, date);
69 }
70
71 public static Calendar getCalendar(int date){
72 Calendar cal = getToday();
73 cal.add(Calendar.DATE, date);
74 return cal;
75 }
76
77 public static int getActualMaximumDate(){
78 Calendar cal = Calendar.getInstance();
79 return cal.getActualMaximum(Calendar.DATE);
80 }
81 }