Java visual calendar Program

Source: Internet
Author: User

Java visual calendar Program

Effect:

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/160A421K-0.jpg "title =" qq 30901174431.jpg "/>

The Code is as follows:

Package com. zyx. date;


Import java. text. DateFormat;

Import java. text. ParseException;

Import java. text. SimpleDateFormat;

Import java. util. Calendar;

Import java. util. Date;

Import java. util. GregorianCalendar;

Import java. util. collections;


/**

* Visualized calendar Program

* @ Author lenovo

*

*/

Public class VisualCalendar {


Public static void main (String [] args ){

System. out. println ("Enter the date in the format of" YYYY )");

/* Get user input */

Required bytes = new bytes (System. in );

String toDay = response. nextLine ();

DateFormat df = new SimpleDateFormat ("yyyy-MM-dd ");

Date date = null;

Try {

Date = df. parse (toDay); // convert string date to date

Calendar calendar = new GregorianCalendar ();

Calendar. setTime (date); // convert a date to a calendar

Int day = calendar. get (Calendar. DATE); // get the day of the current DATE

Calendar. set (Calendar. DATE, 1); // obtain the first day of the DATE.

Int begin = calendar. get (Calendar. DAY_OF_WEEK); // obtain the day of the week on the first day of the date.

Int end = calendar. getActualMaximum (Calendar. DATE); // obtain the last day of the DATE.

System. out. println ("day \ t one \ t Two \ t three \ t four \ t five \ t six ");

/* Display the empty week before the first day */

For (int I = 1; I <begin; I ++ ){

System. out. print ("\ t ");

}

/* Display all dates */

For (int I = 1; I <= end; I ++ ){

If (day = I) {// use * to identify the input date

System. out. print (I + "* \ t ");

} Else {

System. out. print (I + "\ t ");

}

Int week = calendar. get (Calendar. DAY_OF_WEEK); // obtain the day of the week.

If (week = Calendar. SATURDAY) {// line feed on SATURDAY

System. out. println ();

}

Calendar. add (Calendar. DATE, 1); // add one day to the calendar

}

} Catch (ParseException e ){

System. out. println ("Please input according to the format ");

}

}

}


This article is from the "ZYXLOVEJAVA" blog, please be sure to keep this source http://javazyx.blog.51cto.com/1635362/1286674

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.