Calendar class to print calendars using the Calendar class

Source: Internet
Author: User
Tags time in milliseconds

The abstract class Calendar provides a set of methods that allow you to convert time in milliseconds to some useful time component. The calendar cannot create objects directly, but you can use the static method getinstance () to get the Calendars object representing the current date.

Methods of the Calendar class refer to API (Application programming Interface)

The Calendar class uses flexibility to obtain various forms of expression of time and date. The following time will be pushed back 100 days, the date of the year, month, day format.

Calendar s=calendar.getinstance ();    S.add (calendar.day_of_year, 100);    System.out.print (S.get (calendar.year) + "year");    System.out.print (S.get (calendar.month) + "month"); System.out.println (S.get (calendar.day_of_month) + "number");

The results are as follows:

650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M02/8A/1B/wKioL1gnFW7iFoJ8AAAH8mIp0lY785.png-wh_500x0-wm_3 -wmp_4-s_1614681890.png "title=" capture. PNG "alt=" Wkiol1gnfw7ifoj8aaah8mip0ly785.png-wh_50 "/>

Use calendar to get your computer's current calendar:

Date T=new date (); Calendar s=calendar.getinstance (); int a=s.getactualmaximum (calendar.day_of_month); System.out.println ("t \ t two \ t three \ Four \ five \ t six"), S.set (Calendar.day_of_month, 1); int w=s.get (Calendar.day_of_week); for ( int i=1;i<w;i++) {System.out.print ("\ t");} for (int j=1;j<=a;j++) {System.out.print (j+ "\ t"); if (S.get (Calendar.day_of_week) ==calendar.saturday) { System.out.println ();} S.add (calendar.day_of_month,1);}

The resulting format is as follows:

650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M00/8A/1F/wKiom1gnFeXii29ZAAAMheeaeLU711.png-wh_500x0-wm_3 -wmp_4-s_1116912570.png "title=" Capture 2. PNG "alt=" Wkiom1gnfexii29zaaamheeaelu711.png-wh_50 "/>


Calendar class to print calendars using 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.