Java Calendar Model: Enter a date, console display

Source: Internet
Author: User
Tags dateformat idate local time

1  PackageCom.zhen.calendar;2 3 ImportJava.text.DateFormat;4 ImportJava.text.SimpleDateFormat;5 ImportJava.util.Calendar;6 Importjava.util.Date;7 ImportJava.util.GregorianCalendar;8 ImportJava.util.Scanner;9 Ten /* One * Enter a date, console display A * Format: 20140808 -  */ -  the  Public classCalendarmain { -      Public Static voidMain (string[] Argus) -     { -System.out.println ("Please enter a date (format: 20140808):"); +          -Scanner Scanner =NewScanner (system.in); +String stemp = Scanner.nextline ();//Get input characters A          atCalendarmain Calendar =NewCalendarmain (); - Calendar.mycalendar (stemp); -          -Scanner.close ();//close the input stream -     } -      in     Private voidMyCalendar (String stestdate) -     { toDateFormat DF =NewSimpleDateFormat ("YyyyMMdd");//Check Formatting +         Try{ -Date Date =Df.parse (stestdate); theCalendar Calendar =NewGregorianCalendar (); * calendar.settime (date); $             intIyear = Calendar.get (calendar.year);//get the year enteredPanax Notoginseng             intImonth = Calendar.get (calendar.month);//get the month entered -             intIDate = Calendar.get (calendar.date);//get the date entered the              +Calendar.set (calendar.date, 1);//get input Month number 1th A             intIfirstday = Calendar.get (Calendar.day_of_week);//get Input Month 1th number is the day of the week the             intImaxdate = Calendar.getactualmaximum (calendar.date);//get the maximum number of days to enter a month +              -             /* $ //Get local time $ Calendar.settime (New Date ()); - int icuryear = Calendar.get (calendar.year); - int icurmonth = Calendar.get (calendar.month); the int icurdate =-1; - if (icuryear = = Iyear && Icurmonth = = imonth)Wuyi             { the icurdate = Calendar.get (calendar.date); -             } Wu             */ -  AboutSystem.out.println ("--" + Iyear + "year" + (imonth+1) + "month" + "\ n");//month starts from 0 $System.out.println ("t \ t two \ t three \ Four \ five \ t six"); -              -             intj=Ifirstday; -              for(inti=1;i<=imaxdate;i++) A             { +                 if(i = = 1 && i<ifirstday)//number 1th, determine the front empty how much ' \ t ' the                 { -                     intITemp =i; $                      while(ITemp <ifirstday) the                     { theSystem.out.print (' \ t '); theitemp++; the                     } -                 } inString sdate = i<10? "0" +i:i+ "";//formatted Date the                 if(IDate = =i) the                 { AboutSdate + = "* *";//the current input date plus * * the                 } theSystem.out.print (sdate + "\ T"); the                  +                 if(j%7==0)//line Break -                 { the System.out.println ();Bayi                 } theJ + +; the             } -         } -         Catch(Exception e) the         { the              the         } the          -     } the      the}

Java Calendar Model: Enter a date, console display

Related Article

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.