See the Formator class that MAXNO1 (learning flying) in the 9CBS forum. This class has been handled for time dates. I am used to go to a month. So this class has a slight modification. I hope to help others. Date.UTIL;
Import java.util.calendar; import java.util.gregoriancalendar;
Public class formatdate {private static factory string [] weekname = {"Sunday", "Tuesday", Tuesday, Wednesday, "Friday", "Friday", "Saturday"}; private static final string [] datename = {"Year", "Month", "Day", "Time", "Division", "Second"}; Calendar Calendar = Null; Public Static Final Int Year = 0; // Used to identify the year public static final int INT Month = 1; public static final int day = 2; public static final int hour = 3; public static final int minute = 4; public static final int standard = 5;
// Construct the function, generate a calendar object
Public formatdate () {Calendar = new gregoriancalendar ();
} public formatdate (Calendar Calendar) {this.calendar = Calendar;} // year public int getYear () {return caledar.get (Calendar.Year);} // month public int getMonth () {Return Calendar.get (Calendar) .Month 1;} // day public int getday () {return caledar.get (Calendar.day_of_month);} // Get digital-shaped weeks PUBLIC INT getWeek () {return Calendar.Get (Calendar.day_of_week) -1;} // Get the Chinese characters of the Chinese Public String getchWeek () {int week = getWeek (); return weekname [week];} public int gethour () {return caledar.get (Calendar.Hour_of_day);} public INT getminute () {returnate caledar.get (Calendar.minute);} public int getsecond () {return caledar.get (Calendar. Second);}
// Get the date of the year - month-day second format public string getdate () {return getYear () "year" getMonth () "month" getDay () "day";} // get the day of the month public INT GetMonthday () {Return Calendar.GetActualMaximum (Calendar.day_of_month);} / * Get a style of time style @Param style time, "-", ":", * / public string getdate (String style) {ix (Style == null) {return getdate ();} return getYear () style getMonth () style getday ();} public string gettime () {return gethour () "Time" getminute () "分" getsecond () "second";} public string gettime (string style) {if (style == null) {return gettime ();} returnate () style getminute () style getsecond );
} / * Used to increase the @Param Times time to increase the @Param Times time of the year, such as: formatdate.year or 0 is added to the existing year @Param NUM indicates the number of increases, * / public void add (int Times, int NUM) {Switch (Times) {Case Year: Calendar.add (Calendar.Year, Num); Break; Case Month: Calendar.Add (Calendar.Mont, Num); Break; Case Day: Calendar. Add (Calendar.day_of_month, num); Break; Case Hour: Calendar.add (Calendar.Hour_Of_Day, Num); Break; Case Minute: Calendar.Add (Cales Second: Calendar.Add ( Calendar.second, Num); Break; default: system.out.println ("The first parameter is not pair");}} public string toString () {Return getdate () " getTime ();
} public static void main (String [] args) {// Testing 1 for the Month 1 is February, forward, // Specify a date Gregoriancalendar Calendar = New Gregoriancalendar (2004, 11, 1); formatdate fd = new formatdate Calendar;
// Use the current date, take the system date // formatdate fd = new formatdate (); // fd.print (1, 2); system.out.println (fd.getyear ()); system.out.println (FD .getmonth ());
System.out.println (fd.getday ()); system.out.println (fd.getWeek ()); system.out.print (fd.getdate (") "); system.out.println (fd.getchWeek ()); system.out.println (fd.get.Println); system.out.println; system.out.println (fd.getSecond ()); system.out .println (fd.getmonthday ()); System.out.println (fd.gettime (":")); system.out.println (fd.toString ());}
}