import java.text.DateFormatSymbols;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Locale;
public class Test {
public static void main(String[] args) {
//不同地区的程序输出
Locale.setDefault(Locale.CHINESE);
GregorianCalendar d = new GregorianCalendar();
int today = d.get(Calendar.DAY_OF_MONTH);//一月的第几天
int monty = d.get(Calendar.MONTH);//几月
d.set(Calendar.DAY_OF_MONTH, 1);//这个月的第一天
int weekday = d.get(Calendar.DAY_OF_WEEK);//这周的第几天
int firstOfweek = d.getFirstDayOfWeek();//当前地区星期的起始日 1 星期日 2星期一
int indent = 0;
while(weekday != firstOfweek){
indent++;
d.add(Calendar.DAY_OF_MONTH, -1);//前一天
weekday = d.get(Calendar.DAY_OF_WEEK);//这周的第一天
}
String [] weekdayNames = new DateFormatSymbols().getShortWeekdays();
do{
System.out.printf("%4s", weekdayNames[weekday]);
d.add(Calendar.DAY_OF_MONTH, 1);
weekday = d.get(Calendar.DAY_OF_WEEK);
}while(weekday != firstOfweek);
System.out.println();
//日历前的缩进
for (int i = 0; i < indent; i++) {
System.out.print(" ");
}
d.set(Calendar.DAY_OF_MONTH, 1);
do{
int day = d.get(Calendar.DAY_OF_MONTH);
System.out.printf("%3d",day);
if(day == today) System.out.print("*");
else System.out.print(" ");
d.add(Calendar.DAY_OF_MONTH,1);
weekday = d.get(Calendar.DAY_OF_WEEK);
if(weekday == firstOfweek) System.out.println();
}while(d.get(Calendar.MONTH) == monty);
if(weekday == firstOfweek) System.out.println();
}
}