home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-tomcat-addon-1.4.9-installer.exe / JspCalendar.class (.txt) < prev    next >
Encoding:
Java Class File  |  2004-05-17  |  3.4 KB  |  113 lines

  1. package cal;
  2.  
  3. import java.util.Calendar;
  4. import java.util.Date;
  5.  
  6. public class JspCalendar {
  7.    Calendar calendar = null;
  8.    Date currentDate;
  9.  
  10.    public JspCalendar() {
  11.       this.calendar = Calendar.getInstance();
  12.       Date trialTime = new Date();
  13.       this.calendar.setTime(trialTime);
  14.    }
  15.  
  16.    public int getYear() {
  17.       return this.calendar.get(1);
  18.    }
  19.  
  20.    public String getMonth() {
  21.       int m = this.getMonthInt();
  22.       String[] months = new String[]{"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
  23.       return m > 12 ? "Unknown to Man" : months[m - 1];
  24.    }
  25.  
  26.    public String getDay() {
  27.       int x = this.getDayOfWeek();
  28.       String[] days = new String[]{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
  29.       return x > 7 ? "Unknown to Man" : days[x - 1];
  30.    }
  31.  
  32.    public int getMonthInt() {
  33.       return 1 + this.calendar.get(2);
  34.    }
  35.  
  36.    public String getDate() {
  37.       return this.getMonthInt() + "/" + this.getDayOfMonth() + "/" + this.getYear();
  38.    }
  39.  
  40.    public String getCurrentDate() {
  41.       Date dt = new Date();
  42.       this.calendar.setTime(dt);
  43.       return this.getMonthInt() + "/" + this.getDayOfMonth() + "/" + this.getYear();
  44.    }
  45.  
  46.    public String getNextDate() {
  47.       this.calendar.set(5, this.getDayOfMonth() + 1);
  48.       return this.getDate();
  49.    }
  50.  
  51.    public String getPrevDate() {
  52.       this.calendar.set(5, this.getDayOfMonth() - 1);
  53.       return this.getDate();
  54.    }
  55.  
  56.    public String getTime() {
  57.       return this.getHour() + ":" + this.getMinute() + ":" + this.getSecond();
  58.    }
  59.  
  60.    public int getDayOfMonth() {
  61.       return this.calendar.get(5);
  62.    }
  63.  
  64.    public int getDayOfYear() {
  65.       return this.calendar.get(6);
  66.    }
  67.  
  68.    public int getWeekOfYear() {
  69.       return this.calendar.get(3);
  70.    }
  71.  
  72.    public int getWeekOfMonth() {
  73.       return this.calendar.get(4);
  74.    }
  75.  
  76.    public int getDayOfWeek() {
  77.       return this.calendar.get(7);
  78.    }
  79.  
  80.    public int getHour() {
  81.       return this.calendar.get(11);
  82.    }
  83.  
  84.    public int getMinute() {
  85.       return this.calendar.get(12);
  86.    }
  87.  
  88.    public int getSecond() {
  89.       return this.calendar.get(13);
  90.    }
  91.  
  92.    public int getEra() {
  93.       return this.calendar.get(0);
  94.    }
  95.  
  96.    public String getUSTimeZone() {
  97.       String[] zones = new String[]{"Hawaii", "Alaskan", "Pacific", "Mountain", "Central", "Eastern"};
  98.       return zones[10 + this.getZoneOffset()];
  99.    }
  100.  
  101.    public int getZoneOffset() {
  102.       return this.calendar.get(15) / 3600000;
  103.    }
  104.  
  105.    public int getDSTOffset() {
  106.       return this.calendar.get(16) / 3600000;
  107.    }
  108.  
  109.    public int getAMPM() {
  110.       return this.calendar.get(9);
  111.    }
  112. }
  113.