1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package cal;
19
20 import java.util.Calendar;
21 import java.util.Date;
22
23 public class JspCalendar {
24 Calendar calendar = null;
25 Date currentDate;
26
27 public JspCalendar() {
28 calendar = Calendar.getInstance();
29 Date trialTime = new Date();
30 calendar.setTime(trialTime);
31 }
32
33
34 public int getYear() {
35 return calendar.get(Calendar.YEAR);
36 }
37
38 public String getMonth() {
39 int m = getMonthInt();
40 String[] months = new String[]{"January", "February", "March",
41 "April", "May", "June",
42 "July", "August", "September",
43 "October", "November", "December"};
44 if (m > 12)
45 return "Unknown to Man";
46
47 return months[m - 1];
48
49 }
50
51 public String getDay() {
52 int x = getDayOfWeek();
53 String[] days = new String[]{"Sunday", "Monday", "Tuesday", "Wednesday",
54 "Thursday", "Friday", "Saturday"};
55
56 if (x > 7)
57 return "Unknown to Man";
58
59 return days[x - 1];
60
61 }
62
63 public int getMonthInt() {
64 return 1 + calendar.get(Calendar.MONTH);
65 }
66
67 public String getDate() {
68 return getMonthInt() + "/" + getDayOfMonth() + "/" + getYear();
69 }
70
71 public String getCurrentDate() {
72 Date dt = new Date();
73 calendar.setTime(dt);
74 return getMonthInt() + "/" + getDayOfMonth() + "/" + getYear();
75
76 }
77
78 public String getNextDate() {
79 calendar.set(Calendar.DAY_OF_MONTH, getDayOfMonth() + 1);
80 return getDate();
81 }
82
83 public String getPrevDate() {
84 calendar.set(Calendar.DAY_OF_MONTH, getDayOfMonth() - 1);
85 return getDate();
86 }
87
88 public String getTime() {
89 return getHour() + ":" + getMinute() + ":" + getSecond();
90 }
91
92 public int getDayOfMonth() {
93 return calendar.get(Calendar.DAY_OF_MONTH);
94 }
95
96 public int getDayOfYear() {
97 return calendar.get(Calendar.DAY_OF_YEAR);
98 }
99
100 public int getWeekOfYear() {
101 return calendar.get(Calendar.WEEK_OF_YEAR);
102 }
103
104 public int getWeekOfMonth() {
105 return calendar.get(Calendar.WEEK_OF_MONTH);
106 }
107
108 public int getDayOfWeek() {
109 return calendar.get(Calendar.DAY_OF_WEEK);
110 }
111
112 public int getHour() {
113 return calendar.get(Calendar.HOUR_OF_DAY);
114 }
115
116 public int getMinute() {
117 return calendar.get(Calendar.MINUTE);
118 }
119
120
121 public int getSecond() {
122 return calendar.get(Calendar.SECOND);
123 }
124
125
126 public int getEra() {
127 return calendar.get(Calendar.ERA);
128 }
129
130 public String getUSTimeZone() {
131 String[] zones = new String[]{"Hawaii", "Alaskan", "Pacific",
132 "Mountain", "Central", "Eastern"};
133
134 return zones[10 + getZoneOffset()];
135 }
136
137 public int getZoneOffset() {
138 return calendar.get(Calendar.ZONE_OFFSET) / (60 * 60 * 1000);
139 }
140
141
142 public int getDSTOffset() {
143 return calendar.get(Calendar.DST_OFFSET) / (60 * 60 * 1000);
144 }
145
146
147 public int getAMPM() {
148 return calendar.get(Calendar.AM_PM);
149 }
150 }
151
152
153
154
155