今天学了JAVA里的时间调用,一直没弄明白,各位老大能指点下不?谢谢,比如怎么用时间的方法写出个本月日历?
谢谢指点,谢谢!!
楼上的斑竹,你这样说话会影响人气的。
import java.util.*;
class Test {
public static void main(String[] args) {
GregorianCalendar now = new GregorianCalendar();
int today = now.get(Calendar.DAY_OF_MONTH); 获取今天多少号
int month = now.get(Calendar.MONTH); 获取今天是几月
now.set(Calendar.DAY_OF_MONTH,1); 设置一个星期的第1天从星期日开始
int dayOfWeek = now.get(Calendar.DAY_OF_WEEK); 获得今天星期几
System.out.println("\t日\t一\t二\t三\t四\t五\t六");
for (int i = Calendar.SUNDAY; i < dayOfWeek; i++) {
System.out.print("\t");
}
do {
int day = now.get(Calendar.DAY_OF_MONTH);
System.out.print("\t" + day);
if (day == today) {
System.out.print("*");
} else {
System.out.print(" ");
}
if (dayOfWeek == Calendar.SATURDAY) {
System.out.println();
}
now.add(Calendar.DAY_OF_MONTH,1); 现在多少号+1
dayOfWeek = now.get(Calendar.DAY_OF_WEEK); 获取add后的星期几
}while (now.get(Calendar.MONTH) == month); 到31号时会跳到下个月
}
}