| Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 1 | <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 | 
 | 
 | 19 | package cal;
 | 
 | 20 | 
 | 
 | 21 | import java.util.*;
 | 
 | 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 | 
 | 
 | 156 | </pre></body></html>
 |