Java gets the number of days in the month, the specified number of days, and the specified date for the corresponding weekCategory: Java2012-12-25 23:52 3201 People read comments (0) favorite reports J2sej2sejavajavajava gets the number of days in the month gets a specified number of days gets the week of the specified date
Package Com;import java.text.simpledateformat;import java.util.calendar;import java.util.date;/** * @author Gerrard * * public class Testgetweek {public static void main (string[] args) {int currentmaxdays = Getcurrentmonthday (); int Maxdaysbyd ate = Getdaysbyyearmonth (2012, 11); String week = getdayofweekbydate ("2012-12-25"); System.out.println ("Days of the Month:" + currentmaxdays); System.out.println ("November 2012 days:" + maxdaysbydate); System.out.println ("2012-12-25 is:" + week);} /** * Gets the number of days in the month * */public static int getcurrentmonthday () {Calendar a = Calendar.getinstance (); A.set (calendar.date, 1); A.R Oll (Calendar.date,-1); int maxdate = A.get (calendar.date); return maxdate;} /** * Gets the corresponding month days based on year of year * */public static int getdaysbyyearmonth (int year, int month) {Calendar a = calendar.getinstance (); A.set (Calendar.year, year); A.set (Calendar.month, month-1); A.set (calendar.date, 1); A.roll (Calendar.date,-1); int MaxDate = A.get (calendar.date); return maxdate;} /** * Find the day of the week based on the date */public static String GetdayofweekbydaTe (string date) {string dayOfweek = "1"; try {simpledateformat myformatter = new SimpleDateFormat ("YYYY-MM-DD");D ate Myda Te = myformatter.parse (date); SimpleDateFormat formatter = new SimpleDateFormat ("E"); String str = Formatter.format (mydate); DayOfweek = str; } catch (Exception e) {System.out.println ("Error!");} return dayOfweek;}}
Java gets the number of days in the month, the number of days specified, and the specified date for the corresponding week (RPM)