Applet for the Java date class and a console print date for the Calendar class

Source: Internet
Author: User

The Java date class and the Calendar class have a print date applet that can be used directly.

PackageCom.boy.Idate.calendar;ImportJava.text.ParseException;ImportJava.text.SimpleDateFormat;ImportJava.util.Calendar;ImportJava.util.Date;/*** Console Visualization Calendar *@authorOkuda*/PublicClassVisualcalendar {PublicStaticvoidMain (string[] args) {System.out.println ("t \ t two \ t three \ Four \ five \ t six");//Convert string to date and then convert to Calendar standard Date class Calendar c =Calendar.getinstance (); C.settime (Strtodate ("2016-3-12")) );//Gets the day of the one month.int monthday =C.get (calendar.date);//Turn the input date into the month of 1th C.set (calendar.date, 1);//Gets the total number of days for all the month based on the month of the monthint monthallday =C.getactualmaximum (Calendar.day_of_month);//Get the number of weeks of the dayint DayOfWeek =C.get (Calendar.day_of_week);//Control the printing of the first space character based on the number of weeks of the month 1th (if it is Tuesday, empty one block)for (int i = 0; i < dayOfWeek-1; i++) {System.out.print ("\ t"); }//Cycle Days of the monthfor (int i = 1; I <=monthAllDay; i++) {if (i = =MonthDay) {System.out.print ("-"); } System.out.print (i+ "\ T");int w =C.get (Calendar.day_of_week);//2. Change of line every Saturdayif (w==Calendar.saturday) {System.out.println ();}//3. Day of the month plus 1 days c.add (calendar.date, 1public static Date Strtodate (String source) {SimpleDateFormat SDF = new SimpleDateFormat ("Yyyy-mm-dd" Span style= "color: #000000;" >); try {return Sdf.parse (source); } catch (ParseException e) { // TODO auto-generated catch Block E.printstacktrace (); } return null   

Applet for a console printing date for the Java date class and the Calendar class

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.