这是一个在学习北京尚学堂高琪老师的课程后 用于自己学习记录的程序。
}
}
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Scanner;
/**
* 可视化日历程序
* @author Dylan
*
*/
public class VisualCalendar {
public static void main(String[] args) {
System.out.println("请输入日期:(年-月-日):");
Scanner scanner = new Scanner(System.in);
String inputstr = scanner.nextLine();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
try {
Date date = format.parse(inputstr);
Calendar calendar = new GregorianCalendar();
calendar.setTime(date);
Date d = calendar.getTime();
int day = calendar.get(Calendar.DATE);
calendar.set(Calendar.DATE,1);
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<=calendar.getActualMaximum(Calendar.DAY_OF_MONTH);i++) {
if(i==day){
System.out.print('*');
}
System.out.print(i+"\t");
int w = calendar.get(Calendar.DAY_OF_WEEK);
if(w==7){
System.out.println();
}
calendar.add(Calendar.DATE,1);
}
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}