package com.zx.text1;
import java.util.Scanner; // get input window function
import java.util.Calendar;
import java.util.Date; // get the time and date function
java.util.GregorianCalendar import;
import java.text.*;
public class demo3 {
public static void main (String[] args) throws ParseException{
int maxDay = 0;
int firstDay = 0;
int currentDay = 0;
System.out.println ( "Please enter a date in the format: 2019-01-01");
Scanner sc = new Scanner(System.in);
// Get the time format keyboard input
String str = sc.nextLine();
DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Date date = format.parse(str);
// convert string specified date format
Calendar calendar = new GregorianCalendar();
// will be converted to a calendar date
calendar.setTime(date);
maxDay = calendar.getActualMaximum (Calendar.DATE); // get the maximum number of
currentDay = calendar.get(Calendar.DATE);
// current date in the day before yesterday
calendar.set(Calendar.DATE,1);
// set the first day of the current page
firstDay = calendar.get(Calendar.DAY_OF_WEEK);
// current date in a few weeks the first day of the month corresponding
System.out.println("--------------------------------------------------");
System.out.println ( "Sunday \ t Monday \ t Tuesday \ t Wednesday \ t Thursday \ t Friday \ t Saturday");
System.out.println("---------------------------------------------------");
for(int j = 1;j < firstDay;j++) {
// output spaces before the current month
System.out.print("\t");
}
Number of Number // output each day of the month
for(int i = 1;i <= maxDay;i++) {
// represents today's date
if(i == currentDay) {
System.out.print("");
}
System.out.print(i+"\t");
if ((i- (8-firstDay))% 7 == 0) {// 7 day cycle of the output of all the number of
System.out.println("\n");
}
}
}
}