View Javadoc

1   /*
2    * Copyright 2004-2006 the Seasar Foundation and the Others.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
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  }