Source code:
[Java]
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 ();
}
// Calendar Implementation Method
Public void myCalendar (){
GregorianCalendar now = new GregorianCalendar ();
// Obtain a Date object
Date date = new Date ();
// Print the current time
System. out. println (date. toString ());
// Set the current time
Now. setTime (date );
// Obtain the current day from the date
Int toDay = now. get (Calendar. DAY_OF_MONTH );
// Obtain the current month from the date
Int month = now. get (Calendar. MONTH );
// Set the date of now to 1
Now. set (Calendar. DAY_OF_MONTH, 1 );
// Get now as the day of the week
Int week = now. get (Calendar. DAY_OF_WEEK );
// Print the calendar Header
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 with a space less than 10
If (day <10 ){
// If it is the current date, add the mark
If (day = toDay ){
System. out. print ("▲" + day +" ▲\ t ");
} Else {
System. out. print ("" + day + "\ t ");
}
} Else {
// If it is the current date, add the mark
If (day = toDay ){
System. out. print ("▲" + day +" ▲\ t ");
} Else {
System. out. print ("" + day + "\ t ");
}
}
// Line feed for Saturday
If (week = Calendar. 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 );
}
}
}
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 ();
}
// Calendar Implementation Method
Public void myCalendar (){
GregorianCalendar now = new GregorianCalendar ();
// Obtain a Date object
Date date = new Date ();
// Print the current time
System. out. println (date. toString ());
// Set the current time
Now. setTime (date );
// Obtain the current day from the date
Int toDay = now. get (Calendar. DAY_OF_MONTH );
// Obtain the current month from the date
Int month = now. get (Calendar. MONTH );
// Set the date of now to 1
Now. set (Calendar. DAY_OF_MONTH, 1 );
// Get now as the day of the week
Int week = now. get (Calendar. DAY_OF_WEEK );
// Print the calendar Header
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 with a space less than 10
If (day <10 ){
// If it is the current date, add the mark
If (day = toDay ){
System. out. print ("▲" + day +" ▲\ t ");
} Else {
System. out. print ("" + day + "\ t ");
}
} Else {
// If it is the current date, add the mark
If (day = toDay ){
System. out. print ("▲" + day +" ▲\ t ");
} Else {
System. out. print ("" + day + "\ t ");
}
}
// Line feed for Saturday
If (week = Calendar. 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: