ImportJava.text.DateFormat;Importjava.text.ParseException;ImportJava.text.SimpleDateFormat;ImportJava.util.Calendar;Importjava.util.Date;ImportJava.util.GregorianCalendar;ImportJava.util.Scanner;/*** Visual Calendar program **/ Public classVisualcalendar { Public Static voidMain (string[] args) {System.out.println ("Please enter a date (by format: 2015-08-17):"); Scanner Scanner=NewScanner (system.in); String Temp=Scanner.nextline (); //String temp = "2015-8-17";DateFormat format =NewSimpleDateFormat ("Yyyy-mm-dd"); Try{Date Date=Format.parse (temp); //Date converted to calendarCalendar Calender =NewGregorianCalendar (); Calender.settime (date); intDay =Calender.get (calendar.date); Calender.set (Calendar.date,1); intDat_week =Calender.get (Calendar.day_of_week); intMaxdate=Calender.getactualmaximum (calendar.date); System.out.println ("Day \ t two \ t three \ Four \ five \ t six"); for(inti=1;i<dat_week;i++) {System.out.print (' \ t '); } for(inti=1;i<=maxdate;i++) { if(i==Day ) {System.out.print ("*"); } System.out.print (I+ "\ T"); intW =Calender.get (Calendar.day_of_week); if(w==calendar.saturday) {System.out.print (' \ n '); } calender.add (Calendar.date,1); } scanner.close (); } Catch(ParseException e) {//TODO auto-generated Catch blockE.printstacktrace (); } }}
Visual Calendar example of the Calendar class for Java