JAVA print calendar

Source: Internet
Author: User

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:


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.