1 27 28 29 package com.sun.ebank.web; 30 31 import java.util.*; 32 import java.text.SimpleDateFormat ; 33 34 35 39 public class DateHelper { 40 private Calendar cal = null; 41 42 public DateHelper() { 43 Date date = new Date(); 44 cal = new GregorianCalendar(); 45 cal.setTime(date); 46 } 47 48 public void setTime(Date date) { 49 cal.setTime(date); 50 } 51 52 public int getYear() { 53 return cal.get(Calendar.YEAR); 54 } 55 57 public int getMonth() { 58 int calendarMonth = cal.get(Calendar.MONTH); 59 60 return calendarMonthToInt(calendarMonth); 61 } 62 64 public int getDay() { 65 return cal.get(Calendar.DAY_OF_MONTH); 66 } 67 69 public int getHour() { 70 return cal.get(Calendar.HOUR_OF_DAY); 71 } 72 74 public int getMinute() { 75 return cal.get(Calendar.MINUTE); 76 } 77 79 private int calendarMonthToInt(int calendarMonth) { 80 if (calendarMonth == Calendar.JANUARY) { 81 return 1; 82 } else if (calendarMonth == Calendar.FEBRUARY) { 83 return 2; 84 } else if (calendarMonth == Calendar.MARCH) { 85 return 3; 86 } else if (calendarMonth == Calendar.APRIL) { 87 return 4; 88 } else if (calendarMonth == Calendar.MAY) { 89 return 5; 90 } else if (calendarMonth == Calendar.JUNE) { 91 return 6; 92 } else if (calendarMonth == Calendar.JULY) { 93 return 7; 94 } else if (calendarMonth == Calendar.AUGUST) { 95 return 8; 96 } else if (calendarMonth == Calendar.SEPTEMBER) { 97 return 9; 98 } else if (calendarMonth == Calendar.OCTOBER) { 99 return 10; 100 } else if (calendarMonth == Calendar.NOVEMBER) { 101 return 11; 102 } else if (calendarMonth == Calendar.DECEMBER) { 103 return 12; 104 } else { 105 return 1; 106 } 107 } 108 } 110 | Popular Tags |