Scanner scanner=new Scanner(System.in); //创建输入对象
String s=scanner.nextLine(); //获取输入字符串
DateFormat it =new SimpleDateFormat("yyyy-MM-dd");
Date d=it.parse(s);
Calendar c= new GregorianCalendar();
c.setTime(d);
int day=c.get(Calendar.DAY_OF_MONTH);
c.set(Calendar.DAY_OF_MONTH,1);
System.out.println("日\t一\t二\t三\t四\t五\t六");
for(int i=0;i<c.get(Calendar.DAY_OF_WEEK)-1;i++)
{
System.out.print("\t");
}
int max=c.getActualMaximum(Calendar.DATE);
for(int i=1;i<=c.getActualMaximum(Calendar.DATE);i++)
{
if(i==day)
{
System.out.print(i+"*\t"); //在给定日期前加*
}
else
{
System.out.print(c.get(Calendar.DAY_OF_MONTH)+"\t");
}
if(c.get(Calendar.DAY_OF_WEEK)==Calendar.SATURDAY)
{
System.out.println();
}
c.add(Calendar.DAY_OF_MONTH, 1);
}
原文地址:https://blog.51cto.com/14437184/2417909
时间: 2024-10-12 21:03:09