Package Cn.baokx.test;import Java.text.parseexception;import Java.text.simpledateformat;import Java.util.Calendar; Import Java.util.date;import Java.util.gregoriancalendar;public class Test {public static void main (String ... args) {Str ing date_str = "2015-04-10"; Getmycalendar (DATE_STR);} private static void Getmycalendar (String date_str) {SimpleDateFormat SDF = new SimpleDateFormat ("Yyyy-mm-dd"); try {Date d ate = Sdf.parse (DATE_STR); Calendar calendar = new GregorianCalendar (); Calendar.settime (date);//Gets the given time is the number of int day = Calendar.get (calendar.date) ;//Change the date to the month of 1th Calendar.set (calendar.date, 1);//Get the month 1th is the first day of the week int firstdayofweek = Calendar.get (Calendar.day_of_week); /Gets the last day of the month is the number of int lastday = Calendar.getactualmaximum (calendar.date);//More than 6 rows and 7 columns per month to display the full int [] days = new int[6*7];// Array padding value for (int i=1; I <= lastday; i++) {days[i+ (firstDayOfWeek-1)-1] = i;} Print calendar System.out.println ("t \ t two \ t three \ four \ t five \ t six"); for (int i = 0; i < days.length; i++) {if (days[i]!=0) {if (days[i]== Day) {System.out.print ("*");} System.out.print (Days[i]);} System.out.print ("\ t"), if ((i+1)%7==0) {System.out.println ("");}}} catch (ParseException e) {e.printstacktrace ();}}}
Java Print Calendar method