Design a visual calendar with Java

Source: Internet
Author: User
Tags dateformat

Package zhangxuan.test01;

Import Java.text.DateFormat;
Import java.text.ParseException;
Import Java.text.SimpleDateFormat;
Import Java.util.Calendar;
Import Java.util.Date;
Import Java.util.GregorianCalendar;
Import Java.util.Scanner;

public class Lianxi06 {

public static void Main (string[] args) {
System.out.println ("Please enter a date (by format: 2030-3-10):");//output a prompt command
Scanner Scanner = new Scanner (system.in);//Use the scanner class to implement keyboard input (honestly, this thing is not very understanding)
String temp = Scanner.nextline ();

DateFormat format = new SimpleDateFormat ("Yyyy-mm-dd");//DateFormat class to implement the provisions of the date format
try {// This place is not clear with try and catch (Remove direct error)
Date date = Format.parse (temp);//convert date entered into date state
Calendar calendar = new GregorianCalendar ();//Create a new Clendar class to pass the value in date to Calendar
Calendar.settime (date);//Set Date
int day = Calendar.get (calendar.date);//Use the method in the Calendar to get the date entered in the date
Calendar.set (calendar.date, 1);


int maxdate = Calendar.getactualmaximum (calendar.date);//Use the method in the Calendar class to get the maximum date for the current month
System.out.println ("t \ t two \ t three \ Four \ five \ t six");//The output line indicates the day of the week

for (int i=1;i<calendar.get (calendar.day_of_week); i++) {
System.out.print (' \ t ');
}
Before the output date, by determining the day of the week for the month of 1st, and then by outputting the tab stop to achieve the week and date corresponding

for (int i=1;i<=maxdate;i++) {//Output the Calendar table for the current month and output ' * ' before the corresponding date
if (i==day) {//Determines whether the date of the current output is an entry date
System.out.print ("*");
}
System.out.print (i+ "\ t");//cycle print monthly calendar
int w = calendar.get (Calendar.day_of_week);
if (w==calendar.saturday) {//The output is Saturday is a newline
System.out.print (' \ n ');
}
Calendar.add (calendar.date, 1);//To increase the date cycle
}

} catch (ParseException e) {
E.printstacktrace ();

}

}

}

The first blog, do not know what to write, the program has some parts do not understand, and then solve

Design a visual calendar with 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.