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 |
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 21 | import java.util.Calendar;
|
| 22 | import java.util.Date;
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 23 |
|
| 24 | public class JspCalendar {
|
| 25 | Calendar calendar = null;
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 26 |
|
| 27 | public JspCalendar() {
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 28 | calendar = Calendar.getInstance();
|
| 29 | Date trialTime = new Date();
|
| 30 | calendar.setTime(trialTime);
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 31 | }
|
| 32 |
|
| 33 |
|
| 34 | public int getYear() {
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 35 | return calendar.get(Calendar.YEAR);
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 36 | }
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 37 |
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 38 | public String getMonth() {
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 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];
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 48 |
|
| 49 | }
|
| 50 |
|
| 51 | public String getDay() {
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 52 | int x = getDayOfWeek();
|
| 53 | String[] days = new String[] {"Sunday", "Monday", "Tuesday", "Wednesday",
|
| 54 | "Thursday", "Friday", "Saturday"};
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 55 |
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 56 | if (x > 7)
|
| 57 | return "Unknown to Man";
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 58 |
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 59 | return days[x - 1];
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 60 |
|
| 61 | }
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 62 |
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 63 | public int getMonthInt() {
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 64 | return 1 + calendar.get(Calendar.MONTH);
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 65 | }
|
| 66 |
|
| 67 | public String getDate() {
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 68 | return getMonthInt() + "/" + getDayOfMonth() + "/" + getYear();
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 69 | }
|
| 70 |
|
| 71 | public String getCurrentDate() {
|
| 72 | Date dt = new Date ();
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 73 | calendar.setTime (dt);
|
| 74 | return getMonthInt() + "/" + getDayOfMonth() + "/" + getYear();
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 75 |
|
| 76 | }
|
| 77 |
|
| 78 | public String getNextDate() {
|
| 79 | calendar.set (Calendar.DAY_OF_MONTH, getDayOfMonth() + 1);
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 80 | return getDate ();
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 81 | }
|
| 82 |
|
| 83 | public String getPrevDate() {
|
| 84 | calendar.set (Calendar.DAY_OF_MONTH, getDayOfMonth() - 1);
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 85 | return getDate ();
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 86 | }
|
| 87 |
|
| 88 | public String getTime() {
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 89 | return getHour() + ":" + getMinute() + ":" + getSecond();
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 90 | }
|
| 91 |
|
| 92 | public int getDayOfMonth() {
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 93 | return calendar.get(Calendar.DAY_OF_MONTH);
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 94 | }
|
| 95 |
|
| 96 | public int getDayOfYear() {
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 97 | return calendar.get(Calendar.DAY_OF_YEAR);
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 98 | }
|
| 99 |
|
| 100 | public int getWeekOfYear() {
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 101 | return calendar.get(Calendar.WEEK_OF_YEAR);
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 102 | }
|
| 103 |
|
| 104 | public int getWeekOfMonth() {
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 105 | return calendar.get(Calendar.WEEK_OF_MONTH);
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 106 | }
|
| 107 |
|
| 108 | public int getDayOfWeek() {
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 109 | return calendar.get(Calendar.DAY_OF_WEEK);
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 110 | }
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 111 |
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 112 | public int getHour() {
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 113 | return calendar.get(Calendar.HOUR_OF_DAY);
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 114 | }
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 115 |
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 116 | public int getMinute() {
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 117 | return calendar.get(Calendar.MINUTE);
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 118 | }
|
| 119 |
|
| 120 |
|
| 121 | public int getSecond() {
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 122 | return calendar.get(Calendar.SECOND);
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 123 | }
|
| 124 |
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 125 |
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 126 | public int getEra() {
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 127 | return calendar.get(Calendar.ERA);
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 128 | }
|
| 129 |
|
| 130 | public String getUSTimeZone() {
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 131 | String[] zones = new String[] {"Hawaii", "Alaskan", "Pacific",
|
| 132 | "Mountain", "Central", "Eastern"};
|
| 133 |
|
| 134 | return zones[10 + getZoneOffset()];
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 135 | }
|
| 136 |
|
| 137 | public int getZoneOffset() {
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 138 | return calendar.get(Calendar.ZONE_OFFSET)/(60*60*1000);
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 139 | }
|
| 140 |
|
| 141 |
|
| 142 | public int getDSTOffset() {
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 143 | return calendar.get(Calendar.DST_OFFSET)/(60*60*1000);
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 144 | }
|
| 145 |
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 146 |
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 147 | public int getAMPM() {
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 148 | return calendar.get(Calendar.AM_PM);
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 149 | }
|
| 150 | }
|
| 151 |
|
| 152 |
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 153 | </pre></body></html>
|