A class handling class

xiaoxiao2021-03-06  34

Package com.date.hsq;

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 - time PUBLIC STRING GETDATE () {Return getYear () "Year" getMonth () "Month" getDay () "Day";} / * Get some format time style @Param Style time style: "-", ":" Wait * / public string getdate (String style) {r (style == null) {Return getdate ();} return getYear () Style getMonth () style getday ();

} public string gettime () {return gethour () " " getSecond () "second";} public string gettime (string style) {if (style == null) {Return GetTime ();} return gethour () style getSecond ();} / * is used to increase @Param Times time to increase the @Param Times time, such as: formatdate.Year or 0 In order to increase @Param Num in the existing year, * / public void add (int Times, int Num) {switch (Times) {Case Year: Calendar.Add (Calendar.Year, Num); Break Case Month: Calendar.Add (Calendar.month, 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 (Calendar.minute, Num); Break; Case 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) {// Tetting the month of the month 1 is February, pose forward, // Specify a date // Gregoriancalendar Calendar = New Gregoriancalendar (2003, 1, 30); // FormatDate FD = new formatdate; Calendar

// Use the current date, take the system date formatdate fd = new formatdate (); fd.add (5,8000); 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; system.out.println; system.out.println (fd.getsecond ());

System.out.println (fd.gettime (":")); system.out.println (fd.toString ());

}

}

转载请注明原文地址:https://www.9cbs.com/read-66318.html

New Post(0)