目录
Calendar类
Calendar是一个日历抽象类,里面提供了很多操作日历字段的方法(YEAR、MONTH、DAY_OF_MONTH、HOUR)。Calendar类无法直接创建对象使用,里面有一静态方法叫getInstance(),该方法返回了Calendar类的子类对象。静态方法static Calendar getInstance()使用默认时区和语言环境获得一个日历。
Calendar x = Calendar.getInstance();
常用API
什么是日历字段field?
年、月、时、分、秒、月中的某一天
返回给定日历字段的值
public int get(int field)
将给定的日历字段设置为给定值
public void set(int field, int value)
根据日历的规则,为给定的日历字段添加或减去指定时间量
public abstract void add(int field,int amount)
返回一个表示此Calendar时间值(从历元到现在的毫秒偏移量)的Date对象
public Date getTime();
System类
Java.lang.System类中提供了大量静态方法,可以获得与系统相关信息或系统级操作,在System类的API文档中,常用方法有
1.返回以毫秒值为单位的当前时间
public static long currentTimeMillis();
2.将数组中指定的数据拷贝到另一个数组中
public static void arraycopy(Object src, int srcPos, Object dest, int destPos, int lendth);