import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Scanner;
public class VisualCalendar
{
public static void main(String[] args) throws Exception
{
System.out.println("请输入日期 (格式yyyy-MM-dd) : ");
Scanner scanner = new Scanner(System.in);
String inputDate = scanner.nextLine();
DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Date date = format.parse(inputDate);
Calendar calendar = new GregorianCalendar();
calendar.setTime(date);
calendar.set(Calendar.DATE,1);
int sumDays = calendar.getActualMaximum(Calendar.DATE);
System.out.println("日\t一\t二\t三\t四\t五\t六");
for(int i=1;i<calendar.get(Calendar.DAY_OF_WEEK);i++)
{
System.out.print("\t");
}
for(int i=1;i<=sumDays;i++)
{
System.out.print(i+"\t");
if(calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY)
{
System.out.println();
}
calendar.add(Calendar.DATE,1);
}
}
}
运行结果如下: