1 2 3 27 package cal; 28 29 import java.text.DateFormat ; 30 import java.util.*; 31 32 public class JspCalendar { 33 Calendar calendar = null; 34 Date currentDate; 35 36 public JspCalendar() { 37 calendar = Calendar.getInstance(); 38 Date trialTime = new Date(); 39 calendar.setTime(trialTime); 40 } 41 42 43 public int getYear() { 44 return calendar.get(Calendar.YEAR); 45 } 46 47 public String getMonth() { 48 int m = getMonthInt(); 49 String [] months = new String [] { "January", "February", "March", 50 "April", "May", "June", 51 "July", "August", "September", 52 "October", "November", "December" }; 53 if (m > 12) 54 return "Unknown to Man"; 55 56 return months[m - 1]; 57 58 } 59 60 public String getDay() { 61 int x = getDayOfWeek(); 62 String [] days = new String [] {"Sunday", "Monday", "Tuesday", "Wednesday", 63 "Thursday", "Friday", "Saturday"}; 64 65 if (x > 7) 66 return "Unknown to Man"; 67 68 return days[x - 1]; 69 70 } 71 72 public int getMonthInt() { 73 return 1 + calendar.get(Calendar.MONTH); 74 } 75 76 public String getDate() { 77 return getMonthInt() + "/" + getDayOfMonth() + "/" + getYear(); 78 } 79 80 public String getCurrentDate() { 81 Date dt = new Date (); 82 calendar.setTime (dt); 83 return getMonthInt() + "/" + getDayOfMonth() + "/" + getYear(); 84 85 } 86 87 public String getNextDate() { 88 calendar.set (Calendar.DAY_OF_MONTH, getDayOfMonth() + 1); 89 return getDate (); 90 } 91 92 public String getPrevDate() { 93 calendar.set (Calendar.DAY_OF_MONTH, getDayOfMonth() - 1); 94 return getDate (); 95 } 96 97 public String getTime() { 98 return getHour() + ":" + getMinute() + ":" + getSecond(); 99 } 100 101 public int getDayOfMonth() { 102 return calendar.get(Calendar.DAY_OF_MONTH); 103 } 104 105 public int getDayOfYear() { 106 return calendar.get(Calendar.DAY_OF_YEAR); 107 } 108 109 public int getWeekOfYear() { 110 return calendar.get(Calendar.WEEK_OF_YEAR); 111 } 112 113 public int getWeekOfMonth() { 114 return calendar.get(Calendar.WEEK_OF_MONTH); 115 } 116 117 public int getDayOfWeek() { 118 return calendar.get(Calendar.DAY_OF_WEEK); 119 } 120 121 public int getHour() { 122 return calendar.get(Calendar.HOUR_OF_DAY); 123 } 124 125 public int getMinute() { 126 return calendar.get(Calendar.MINUTE); 127 } 128 129 130 public int getSecond() { 131 return calendar.get(Calendar.SECOND); 132 } 133 134 135 public int getEra() { 136 return calendar.get(Calendar.ERA); 137 } 138 139 public String getUSTimeZone() { 140 String [] zones = new String [] {"Hawaii", "Alaskan", "Pacific", 141 "Mountain", "Central", "Eastern"}; 142 143 return zones[10 + getZoneOffset()]; 144 } 145 146 public int getZoneOffset() { 147 return calendar.get(Calendar.ZONE_OFFSET)/(60*60*1000); 148 } 149 150 151 public int getDSTOffset() { 152 return calendar.get(Calendar.DST_OFFSET)/(60*60*1000); 153 } 154 155 156 public int getAMPM() { 157 return calendar.get(Calendar.AM_PM); 158 } 159 } 160 161 162 163 164 165 | Popular Tags |