source: nutchez-0.1/tomcat/webapps/examples/WEB-INF/classes/cal/JspCalendar.java @ 91

Last change on this file since 91 was 66, checked in by waue, 15 years ago

NutchEz - an easy way to nutch

File size: 3.5 KB
RevLine 
[66]1/*
2* Licensed to the Apache Software Foundation (ASF) under one or more
3* contributor license agreements.  See the NOTICE file distributed with
4* this work for additional information regarding copyright ownership.
5* The ASF licenses this file to You under the Apache License, Version 2.0
6* (the "License"); you may not use this file except in compliance with
7* the License.  You may obtain a copy of the License at
8*
9*     http://www.apache.org/licenses/LICENSE-2.0
10*
11* Unless required by applicable law or agreed to in writing, software
12* distributed under the License is distributed on an "AS IS" BASIS,
13* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14* See the License for the specific language governing permissions and
15* limitations under the License.
16*/
17
18package cal;
19
20import java.util.*;
21
22public class JspCalendar {
23    Calendar  calendar = null;
24    Date currentDate;
25
26    public JspCalendar() {
27  calendar = Calendar.getInstance();
28  Date trialTime = new Date();
29  calendar.setTime(trialTime);
30    }
31
32
33    public int getYear() {
34  return calendar.get(Calendar.YEAR);
35    }
36   
37    public String getMonth() {
38  int m = getMonthInt();
39  String[] months = new String [] { "January", "February", "March",
40          "April", "May", "June",
41          "July", "August", "September",
42          "October", "November", "December" };
43  if (m > 12)
44      return "Unknown to Man";
45 
46  return months[m - 1];
47
48    }
49
50    public String getDay() {
51  int x = getDayOfWeek();
52  String[] days = new String[] {"Sunday", "Monday", "Tuesday", "Wednesday", 
53              "Thursday", "Friday", "Saturday"};
54
55  if (x > 7)
56      return "Unknown to Man";
57
58  return days[x - 1];
59
60    }
61   
62    public int getMonthInt() {
63  return 1 + calendar.get(Calendar.MONTH);
64    }
65
66    public String getDate() {
67  return getMonthInt() + "/" + getDayOfMonth() + "/" +  getYear(); 
68    }
69
70    public String getCurrentDate() {
71        Date dt = new Date ();
72  calendar.setTime (dt);
73  return getMonthInt() + "/" + getDayOfMonth() + "/" +  getYear();
74
75    }
76
77    public String getNextDate() {
78        calendar.set (Calendar.DAY_OF_MONTH, getDayOfMonth() + 1);
79  return getDate ();
80    }
81
82    public String getPrevDate() {
83        calendar.set (Calendar.DAY_OF_MONTH, getDayOfMonth() - 1);
84  return getDate ();
85    }
86
87    public String getTime() {
88  return getHour() + ":" + getMinute() + ":" + getSecond();
89    }
90
91    public int getDayOfMonth() {
92  return calendar.get(Calendar.DAY_OF_MONTH);
93    }
94
95    public int getDayOfYear() {
96  return calendar.get(Calendar.DAY_OF_YEAR);
97    }
98
99    public int getWeekOfYear() {
100  return calendar.get(Calendar.WEEK_OF_YEAR);
101    }
102
103    public int getWeekOfMonth() {
104  return calendar.get(Calendar.WEEK_OF_MONTH);
105    }
106
107    public int getDayOfWeek() {
108  return calendar.get(Calendar.DAY_OF_WEEK);
109    }
110     
111    public int getHour() {
112  return calendar.get(Calendar.HOUR_OF_DAY);
113    }
114   
115    public int getMinute() {
116  return calendar.get(Calendar.MINUTE);
117    }
118
119
120    public int getSecond() {
121  return calendar.get(Calendar.SECOND);
122    }
123
124 
125    public int getEra() {
126  return calendar.get(Calendar.ERA);
127    }
128
129    public String getUSTimeZone() {
130  String[] zones = new String[] {"Hawaii", "Alaskan", "Pacific",
131               "Mountain", "Central", "Eastern"};
132 
133  return zones[10 + getZoneOffset()];
134    }
135
136    public int getZoneOffset() {
137  return calendar.get(Calendar.ZONE_OFFSET)/(60*60*1000);
138    }
139
140
141    public int getDSTOffset() {
142  return calendar.get(Calendar.DST_OFFSET)/(60*60*1000);
143    }
144
145   
146    public int getAMPM() {
147  return calendar.get(Calendar.AM_PM);
148    }
149}
150
151
152
153
154
Note: See TracBrowser for help on using the repository browser.