import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
public class RiLi {
public static void main(String[] args) {
System.out.println("请输入日期(格式:2018-01-01):");
String temp="2018-02-01";
DateFormat df =new SimpleDateFormat("yyyy-MM-dd");
System.out.print("日\t一 \t二\t三\t四\t五\t六");
System.out.println();
try {
Date date=df.parse(temp);
GregorianCalendar calendar=new GregorianCalendar();
calendar.setTime(date);
calendar.set(calendar.DATE, 1);
int maxDay=calendar.getActualMaximum(calendar.DATE);
int today=calendar.get(calendar.DAY_OF_WEEK);
for(int j=1;j<today;j++)
{
System.out.print("\t");
}
for(int i=1;i<=maxDay;i++)
{
System.out.print(i+"\t");
calendar.add(calendar.DATE, 1);
if(today==Calendar.SATURDAY){
System.out.println();
}
}
} catch (ParseException e) {
}
}
}
添加回答
举报
0/150
提交
取消