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