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