blob: 3c04fd15d10ca63c7870c36ec21843a5492ff6e5 [file] [log] [blame]
Hongqing Liufd5ee812014-05-10 16:32:51 +08001<html><body><pre>
2/*
3* Licensed to the Apache Software Foundation (ASF) under one or more
4* contributor license agreements. See the NOTICE file distributed with
5* this work for additional information regarding copyright ownership.
6* The ASF licenses this file to You under the Apache License, Version 2.0
7* (the "License"); you may not use this file except in compliance with
8* the License. You may obtain a copy of the License at
9*
10* http://www.apache.org/licenses/LICENSE-2.0
11*
12* Unless required by applicable law or agreed to in writing, software
13* distributed under the License is distributed on an "AS IS" BASIS,
14* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15* See the License for the specific language governing permissions and
16* limitations under the License.
17*/
18
19package cal;
20
刘洪青6266f992017-05-15 21:21:03 +080021import java.util.Calendar;
22import java.util.Date;
Hongqing Liufd5ee812014-05-10 16:32:51 +080023
24public class JspCalendar {
25 Calendar calendar = null;
Hongqing Liufd5ee812014-05-10 16:32:51 +080026
27 public JspCalendar() {
刘洪青6266f992017-05-15 21:21:03 +080028 calendar = Calendar.getInstance();
29 Date trialTime = new Date();
30 calendar.setTime(trialTime);
Hongqing Liufd5ee812014-05-10 16:32:51 +080031 }
32
33
34 public int getYear() {
刘洪青6266f992017-05-15 21:21:03 +080035 return calendar.get(Calendar.YEAR);
Hongqing Liufd5ee812014-05-10 16:32:51 +080036 }
刘洪青6266f992017-05-15 21:21:03 +080037
Hongqing Liufd5ee812014-05-10 16:32:51 +080038 public String getMonth() {
刘洪青6266f992017-05-15 21:21:03 +080039 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];
Hongqing Liufd5ee812014-05-10 16:32:51 +080048
49 }
50
51 public String getDay() {
刘洪青6266f992017-05-15 21:21:03 +080052 int x = getDayOfWeek();
53 String[] days = new String[] {"Sunday", "Monday", "Tuesday", "Wednesday",
54 "Thursday", "Friday", "Saturday"};
Hongqing Liufd5ee812014-05-10 16:32:51 +080055
刘洪青6266f992017-05-15 21:21:03 +080056 if (x > 7)
57 return "Unknown to Man";
Hongqing Liufd5ee812014-05-10 16:32:51 +080058
刘洪青6266f992017-05-15 21:21:03 +080059 return days[x - 1];
Hongqing Liufd5ee812014-05-10 16:32:51 +080060
61 }
刘洪青6266f992017-05-15 21:21:03 +080062
Hongqing Liufd5ee812014-05-10 16:32:51 +080063 public int getMonthInt() {
刘洪青6266f992017-05-15 21:21:03 +080064 return 1 + calendar.get(Calendar.MONTH);
Hongqing Liufd5ee812014-05-10 16:32:51 +080065 }
66
67 public String getDate() {
刘洪青6266f992017-05-15 21:21:03 +080068 return getMonthInt() + "/" + getDayOfMonth() + "/" + getYear();
Hongqing Liufd5ee812014-05-10 16:32:51 +080069 }
70
71 public String getCurrentDate() {
72 Date dt = new Date ();
刘洪青6266f992017-05-15 21:21:03 +080073 calendar.setTime (dt);
74 return getMonthInt() + "/" + getDayOfMonth() + "/" + getYear();
Hongqing Liufd5ee812014-05-10 16:32:51 +080075
76 }
77
78 public String getNextDate() {
79 calendar.set (Calendar.DAY_OF_MONTH, getDayOfMonth() + 1);
刘洪青6266f992017-05-15 21:21:03 +080080 return getDate ();
Hongqing Liufd5ee812014-05-10 16:32:51 +080081 }
82
83 public String getPrevDate() {
84 calendar.set (Calendar.DAY_OF_MONTH, getDayOfMonth() - 1);
刘洪青6266f992017-05-15 21:21:03 +080085 return getDate ();
Hongqing Liufd5ee812014-05-10 16:32:51 +080086 }
87
88 public String getTime() {
刘洪青6266f992017-05-15 21:21:03 +080089 return getHour() + ":" + getMinute() + ":" + getSecond();
Hongqing Liufd5ee812014-05-10 16:32:51 +080090 }
91
92 public int getDayOfMonth() {
刘洪青6266f992017-05-15 21:21:03 +080093 return calendar.get(Calendar.DAY_OF_MONTH);
Hongqing Liufd5ee812014-05-10 16:32:51 +080094 }
95
96 public int getDayOfYear() {
刘洪青6266f992017-05-15 21:21:03 +080097 return calendar.get(Calendar.DAY_OF_YEAR);
Hongqing Liufd5ee812014-05-10 16:32:51 +080098 }
99
100 public int getWeekOfYear() {
刘洪青6266f992017-05-15 21:21:03 +0800101 return calendar.get(Calendar.WEEK_OF_YEAR);
Hongqing Liufd5ee812014-05-10 16:32:51 +0800102 }
103
104 public int getWeekOfMonth() {
刘洪青6266f992017-05-15 21:21:03 +0800105 return calendar.get(Calendar.WEEK_OF_MONTH);
Hongqing Liufd5ee812014-05-10 16:32:51 +0800106 }
107
108 public int getDayOfWeek() {
刘洪青6266f992017-05-15 21:21:03 +0800109 return calendar.get(Calendar.DAY_OF_WEEK);
Hongqing Liufd5ee812014-05-10 16:32:51 +0800110 }
刘洪青6266f992017-05-15 21:21:03 +0800111
Hongqing Liufd5ee812014-05-10 16:32:51 +0800112 public int getHour() {
刘洪青6266f992017-05-15 21:21:03 +0800113 return calendar.get(Calendar.HOUR_OF_DAY);
Hongqing Liufd5ee812014-05-10 16:32:51 +0800114 }
刘洪青6266f992017-05-15 21:21:03 +0800115
Hongqing Liufd5ee812014-05-10 16:32:51 +0800116 public int getMinute() {
刘洪青6266f992017-05-15 21:21:03 +0800117 return calendar.get(Calendar.MINUTE);
Hongqing Liufd5ee812014-05-10 16:32:51 +0800118 }
119
120
121 public int getSecond() {
刘洪青6266f992017-05-15 21:21:03 +0800122 return calendar.get(Calendar.SECOND);
Hongqing Liufd5ee812014-05-10 16:32:51 +0800123 }
124
刘洪青6266f992017-05-15 21:21:03 +0800125
Hongqing Liufd5ee812014-05-10 16:32:51 +0800126 public int getEra() {
刘洪青6266f992017-05-15 21:21:03 +0800127 return calendar.get(Calendar.ERA);
Hongqing Liufd5ee812014-05-10 16:32:51 +0800128 }
129
130 public String getUSTimeZone() {
刘洪青6266f992017-05-15 21:21:03 +0800131 String[] zones = new String[] {"Hawaii", "Alaskan", "Pacific",
132 "Mountain", "Central", "Eastern"};
133
134 return zones[10 + getZoneOffset()];
Hongqing Liufd5ee812014-05-10 16:32:51 +0800135 }
136
137 public int getZoneOffset() {
刘洪青6266f992017-05-15 21:21:03 +0800138 return calendar.get(Calendar.ZONE_OFFSET)/(60*60*1000);
Hongqing Liufd5ee812014-05-10 16:32:51 +0800139 }
140
141
142 public int getDSTOffset() {
刘洪青6266f992017-05-15 21:21:03 +0800143 return calendar.get(Calendar.DST_OFFSET)/(60*60*1000);
Hongqing Liufd5ee812014-05-10 16:32:51 +0800144 }
145
刘洪青6266f992017-05-15 21:21:03 +0800146
Hongqing Liufd5ee812014-05-10 16:32:51 +0800147 public int getAMPM() {
刘洪青6266f992017-05-15 21:21:03 +0800148 return calendar.get(Calendar.AM_PM);
Hongqing Liufd5ee812014-05-10 16:32:51 +0800149 }
150}
151
152
Hongqing Liufd5ee812014-05-10 16:32:51 +0800153</pre></body></html>