Source code:
Import Java. util. calendar; import Java. util. date; import Java. util. gregoriancalendar; public class mydate {public static void main (string [] ARGs) {mydate date = new mydate (); date. mycalendar () ;}// method for implementing the calendar public void mycalendar () {gregoriancalendar now = new gregoriancalendar (); // obtain a date object date = new date (); // print the current time system. out. println (date. tostring (); // set the current time now. settime (date); // obtain the current day int today = now from the date. get (calendar. day_of_month); // retrieves the current month int month = now from the date. get (calendar. month); // set the date of now to 1now. set (calendar. day_of_month, 1); // get now is the day of the week int week = now. get (calendar. day_of_week); // print the calendar header to indicate system. out. println ("day \ t one \ t Two \ t three \ t four \ t five \ t six"); // print the space before the current date for (INT I = calendar. sunday; I <week; I ++) {system. out. print ("\ t");} // print the calendar subject while (now. get (calendar. month) = month) {int day = now. get (calendar. day_of_month); // alignment the output calendar. If it is less than 10, add a space if (day <10) {// if it is the current date, add if (Day = Today) {system. out. print ("▲" + day +" ▲\ t ");} else {system. out. print ("" + day + "\ t") ;}} else {// if it is the current date, add the IF (Day = Today) {system. out. print ("▲" + day +" ▲\ t ");} else {system. out. print ("" + day + "\ t") ;}// if it is Saturday, wrap it if (week = calendar ar. saturday) {system. out. println ();} // after each output date, add the date to one day now. add (calendar. day_of_month, 1); // obtain the day of the week again. Week = now. get (calendar. day_of_week );}}}
Output result: