Java Print Calendar method

Source: Internet
Author: User

Package Cn.baokx.test;import Java.text.parseexception;import Java.text.simpledateformat;import Java.util.Calendar; Import Java.util.date;import Java.util.gregoriancalendar;public class Test {public static void main (String ... args) {Str ing date_str = "2015-04-10"; Getmycalendar (DATE_STR);} private static void Getmycalendar (String date_str) {SimpleDateFormat SDF = new SimpleDateFormat ("Yyyy-mm-dd"); try {Date d ate = Sdf.parse (DATE_STR); Calendar calendar = new GregorianCalendar (); Calendar.settime (date);//Gets the given time is the number of int day = Calendar.get (calendar.date) ;//Change the date to the month of 1th Calendar.set (calendar.date, 1);//Get the month 1th is the first day of the week int firstdayofweek = Calendar.get (Calendar.day_of_week); /Gets the last day of the month is the number of int lastday = Calendar.getactualmaximum (calendar.date);//More than 6 rows and 7 columns per month to display the full int [] days = new int[6*7];// Array padding value for (int i=1; I <= lastday; i++) {days[i+ (firstDayOfWeek-1)-1] = i;} Print calendar System.out.println ("t \ t two \ t three \ four \ t five \ t six"); for (int i = 0; i < days.length; i++) {if (days[i]!=0) {if (days[i]== Day) {System.out.print ("*");} System.out.print (Days[i]);} System.out.print ("\ t"), if ((i+1)%7==0) {System.out.println ("");}}} catch (ParseException e) {e.printstacktrace ();}}}

Java Print Calendar method

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.