001: /*
002: * Copyright 2004 The Apache Software Foundation
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package cal;
018:
019: import java.text.DateFormat;
020: import java.util.*;
021:
022: public class JspCalendar {
023: Calendar calendar = null;
024: Date currentDate;
025:
026: public JspCalendar() {
027: calendar = Calendar.getInstance();
028: Date trialTime = new Date();
029: calendar.setTime(trialTime);
030: }
031:
032: public int getYear() {
033: return calendar.get(Calendar.YEAR);
034: }
035:
036: public String getMonth() {
037: int m = getMonthInt();
038: String[] months = new String[] { "January", "February",
039: "March", "April", "May", "June", "July", "August",
040: "September", "October", "November", "December" };
041: if (m > 12)
042: return "Unknown to Man";
043:
044: return months[m - 1];
045:
046: }
047:
048: public String getDay() {
049: int x = getDayOfWeek();
050: String[] days = new String[] { "Sunday", "Monday", "Tuesday",
051: "Wednesday", "Thursday", "Friday", "Saturday" };
052:
053: if (x > 7)
054: return "Unknown to Man";
055:
056: return days[x - 1];
057:
058: }
059:
060: public int getMonthInt() {
061: return 1 + calendar.get(Calendar.MONTH);
062: }
063:
064: public String getDate() {
065: return getMonthInt() + "/" + getDayOfMonth() + "/" + getYear();
066: }
067:
068: public String getCurrentDate() {
069: Date dt = new Date();
070: calendar.setTime(dt);
071: return getMonthInt() + "/" + getDayOfMonth() + "/" + getYear();
072:
073: }
074:
075: public String getNextDate() {
076: calendar.set(Calendar.DAY_OF_MONTH, getDayOfMonth() + 1);
077: return getDate();
078: }
079:
080: public String getPrevDate() {
081: calendar.set(Calendar.DAY_OF_MONTH, getDayOfMonth() - 1);
082: return getDate();
083: }
084:
085: public String getTime() {
086: return getHour() + ":" + getMinute() + ":" + getSecond();
087: }
088:
089: public int getDayOfMonth() {
090: return calendar.get(Calendar.DAY_OF_MONTH);
091: }
092:
093: public int getDayOfYear() {
094: return calendar.get(Calendar.DAY_OF_YEAR);
095: }
096:
097: public int getWeekOfYear() {
098: return calendar.get(Calendar.WEEK_OF_YEAR);
099: }
100:
101: public int getWeekOfMonth() {
102: return calendar.get(Calendar.WEEK_OF_MONTH);
103: }
104:
105: public int getDayOfWeek() {
106: return calendar.get(Calendar.DAY_OF_WEEK);
107: }
108:
109: public int getHour() {
110: return calendar.get(Calendar.HOUR_OF_DAY);
111: }
112:
113: public int getMinute() {
114: return calendar.get(Calendar.MINUTE);
115: }
116:
117: public int getSecond() {
118: return calendar.get(Calendar.SECOND);
119: }
120:
121: public int getEra() {
122: return calendar.get(Calendar.ERA);
123: }
124:
125: public String getUSTimeZone() {
126: String[] zones = new String[] { "Hawaii", "Alaskan", "Pacific",
127: "Mountain", "Central", "Eastern" };
128:
129: return zones[10 + getZoneOffset()];
130: }
131:
132: public int getZoneOffset() {
133: return calendar.get(Calendar.ZONE_OFFSET) / (60 * 60 * 1000);
134: }
135:
136: public int getDSTOffset() {
137: return calendar.get(Calendar.DST_OFFSET) / (60 * 60 * 1000);
138: }
139:
140: public int getAMPM() {
141: return calendar.get(Calendar.AM_PM);
142: }
143: }
|