Visual Calendar example of the Calendar class for Java

Source: Internet
Author: User
Tags dateformat

ImportJava.text.DateFormat;Importjava.text.ParseException;ImportJava.text.SimpleDateFormat;ImportJava.util.Calendar;Importjava.util.Date;ImportJava.util.GregorianCalendar;ImportJava.util.Scanner;/*** Visual Calendar program **/ Public classVisualcalendar { Public Static voidMain (string[] args) {System.out.println ("Please enter a date (by format: 2015-08-17):"); Scanner Scanner=NewScanner (system.in); String Temp=Scanner.nextline (); //String temp = "2015-8-17";DateFormat format =NewSimpleDateFormat ("Yyyy-mm-dd"); Try{Date Date=Format.parse (temp); //Date converted to calendarCalendar Calender =NewGregorianCalendar ();                    Calender.settime (date); intDay =Calender.get (calendar.date); Calender.set (Calendar.date,1); intDat_week =Calender.get (Calendar.day_of_week); intMaxdate=Calender.getactualmaximum (calendar.date); System.out.println ("Day \ t two \ t three \ Four \ five \ t six");  for(inti=1;i<dat_week;i++) {System.out.print (' \ t '); }                         for(inti=1;i<=maxdate;i++)            {                if(i==Day ) {System.out.print ("*"); } System.out.print (I+ "\ T"); intW =Calender.get (Calendar.day_of_week); if(w==calendar.saturday) {System.out.print (' \ n '); } calender.add (Calendar.date,1);        } scanner.close (); } Catch(ParseException e) {//TODO auto-generated Catch blockE.printstacktrace (); }    }}

Visual Calendar example of the Calendar class for Java

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.