package Date;
import java.text.DateFormat;
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 ya
*
*/
public class Test02 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入日期,格式是1991-12-01");
String str = sc.next();
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
Date d = new Date();
try {
d = df.parse(str);
Calendar cal = new GregorianCalendar();
cal.setTime(d);
int today=cal.get(Calendar.DATE);
cal.set(Calendar.DATE, 1);
int maxd = cal.getActualMaximum(Calendar.DATE);
System.out.println("日\t一\t二\t三\t四\t五\t六");
for (int i = 1; i < cal.get(Calendar.DAY_OF_WEEK); i++) {
System.out.print("\t");
}
for (int j = 1; j <= maxd; j++) {
if(j==today){
System.out.print("*");
}
System.out.print(j + "\t");
int week = cal.get(Calendar.DAY_OF_WEEK);
if (week==Calendar.SATURDAY) {
System.out.println();
}
cal.add(Calendar.DATE, 1);
}
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
|
|