package JAVA2;
import java.util.Calendar;
import java.util.GregorianCalendar;
public class ch4testCalendar {
public static void main(String [] args){
/**
* 获取默认地区的时间
*/
GregorianCalendar d=new GregorianCalendar();
int today=d.get(Calendar.DAY_OF_MONTH);
System.out.println("今天的日期为:"+today+"号");
int month=d.get(Calendar.MONTH);
System.out.println("今天的月分为:"+(month+1)+"月");//月份需要+1
int year=d.get(Calendar.YEAR);
System.out.println("今天是:"+year+"年");
d.set(Calendar.DAY_OF_MONTH, 1);//将D设置为这个月的第一天
int week=d.get(Calendar.DAY_OF_WEEK);//获取今天是星期几
System.out.println("今天是星期:"+week);
}
}
阅读(1420) | 评论(0) | 转发(0) |