1 PackageCom.example.administrator.dayofmonth;2 3 ImportJava.text.SimpleDateFormat;4 ImportJava.util.Calendar;5 Importjava.util.Date;6 7 /**8 * Created by fire dragon naked Mr. on 2017/4/11 0011.9 */Ten One Public classNumber_of_days { A - /** - * Get the number of days in the month the */ - Public Static intGetcurrentmonthday () { - -Calendar A =calendar.getinstance (); +A.set (Calendar.date, 1); -A.roll (Calendar.date, 1); + intMaxDate =A.get (calendar.date); A returnmaxdate; at } - - /** - * The number of days to obtain the corresponding month according to the year and month - */ - Public Static intGetdaysbyyearmonth (intYearintmonth) { in -Calendar A =calendar.getinstance (); to A.set (calendar.year, year); +A.set (Calendar.month, month-1); -A.set (Calendar.date, 1); theA.roll (Calendar.date, 1); * intMaxDate =A.get (calendar.date); $ returnmaxdate;Panax Notoginseng } - the /** + * Find the day of the week based on the date A */ the Public Staticstring Getdayofweekbydate (string date) { +String DayOfweek = "1"; - Try { $SimpleDateFormat MyFormatter =NewSimpleDateFormat ("Yyyy-mm-dd"); $Date mydate =myformatter.parse (date); -SimpleDateFormat formatter =NewSimpleDateFormat ("E"); -String str =Formatter.format (mydate); theDayOfweek =str; - Wuyi}Catch(Exception e) { theSYSTEM.OUT.PRINTLN ("Error!")); - } Wu returnDayOfweek; - } About $}
Java gets the number of days in the month, the specified number of days, and the specified date for the corresponding week.