KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > ebank > web > DateHelper


1 /*
2  * Copyright (c) 2004 Sun Microsystems, Inc. All rights reserved. U.S.
3  * Government Rights - Commercial software. Government users are subject
4  * to the Sun Microsystems, Inc. standard license agreement and
5  * applicable provisions of the FAR and its supplements. Use is subject
6  * to license terms.
7  *
8  * This distribution may include materials developed by third parties.
9  * Sun, Sun Microsystems, the Sun logo, Java and J2EE are trademarks
10  * or registered trademarks of Sun Microsystems, Inc. in the U.S. and
11  * other countries.
12  *
13  * Copyright (c) 2004 Sun Microsystems, Inc. Tous droits reserves.
14  *
15  * Droits du gouvernement americain, utilisateurs gouvernementaux - logiciel
16  * commercial. Les utilisateurs gouvernementaux sont soumis au contrat de
17  * licence standard de Sun Microsystems, Inc., ainsi qu'aux dispositions
18  * en vigueur de la FAR (Federal Acquisition Regulations) et des
19  * supplements a celles-ci. Distribue par des licences qui en
20  * restreignent l'utilisation.
21  *
22  * Cette distribution peut comprendre des composants developpes par des
23  * tierces parties. Sun, Sun Microsystems, le logo Sun, Java et J2EE
24  * sont des marques de fabrique ou des marques deposees de Sun
25  * Microsystems, Inc. aux Etats-Unis et dans d'autres pays.
26  */

27
28
29 package com.sun.ebank.web;
30
31 import java.util.*;
32 import java.text.SimpleDateFormat JavaDoc;
33
34
35 /**
36  * This class contains helper methods for dealing with
37  * Date objects.
38  */

39 public class DateHelper {
40     private Calendar cal = null;
41
42     public DateHelper() {
43         Date date = new Date();
44         cal = new GregorianCalendar();
45         cal.setTime(date);
46     }
47
48     public void setTime(Date date) {
49         cal.setTime(date);
50     }
51
52     public int getYear() {
53         return cal.get(Calendar.YEAR);
54     }
55      // getYear
56

57     public int getMonth() {
58         int calendarMonth = cal.get(Calendar.MONTH);
59
60         return calendarMonthToInt(calendarMonth);
61     }
62      // getMonth
63

64     public int getDay() {
65         return cal.get(Calendar.DAY_OF_MONTH);
66     }
67      // getDay
68

69     public int getHour() {
70         return cal.get(Calendar.HOUR_OF_DAY);
71     }
72      // geHour
73

74     public int getMinute() {
75         return cal.get(Calendar.MINUTE);
76     }
77      // geMinute
78

79     private int calendarMonthToInt(int calendarMonth) {
80         if (calendarMonth == Calendar.JANUARY) {
81             return 1;
82         } else if (calendarMonth == Calendar.FEBRUARY) {
83             return 2;
84         } else if (calendarMonth == Calendar.MARCH) {
85             return 3;
86         } else if (calendarMonth == Calendar.APRIL) {
87             return 4;
88         } else if (calendarMonth == Calendar.MAY) {
89             return 5;
90         } else if (calendarMonth == Calendar.JUNE) {
91             return 6;
92         } else if (calendarMonth == Calendar.JULY) {
93             return 7;
94         } else if (calendarMonth == Calendar.AUGUST) {
95             return 8;
96         } else if (calendarMonth == Calendar.SEPTEMBER) {
97             return 9;
98         } else if (calendarMonth == Calendar.OCTOBER) {
99             return 10;
100         } else if (calendarMonth == Calendar.NOVEMBER) {
101             return 11;
102         } else if (calendarMonth == Calendar.DECEMBER) {
103             return 12;
104         } else {
105             return 1;
106         }
107     }
108      // calendarMonthToInt
109
}
110  // class
111
Popular Tags