一 、Date
常用构造方法:
public Date();
public Date(long date);
常用成员方法:
public String toString();//被重写
public long getTime();//返回距1970.01.01 00:00:00的毫秒数
二 、DateFormat(java.text)
概述:
时间或日期的格式化的抽象类,只能用其子类SimpleDateFormat实例化
三 、SimpleDateFormat(java.text)
常用构造:
public SimpleDateFormat();
/*
* pattern 为格式化语句,
* 例:new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");
*/
public SimpleDateFormat(String pattern);
常用成员方法:
public String format(Date d);//以指定格式返回日期的字符串
public Date parse(String s);//将字符串日期解析为Date
四、 Calendar(java.util)
概述:
抽象类,无构造方法,其子类GregorianCalendar构造方法过于复杂,获取对象推荐使用其静态方法public static Ccalendar getInstance();
常用成员方法:
public int get(int field);//返回该实例下某个字段,参数为该类下静态常量,如Calendar.MONTH
public void add(int field,int amount);//为该实例某个字段添加值
public void set(int field,int amount);//为该实例某个字段修改值
public Date getTime();//将该Calendar对象转化为Date对象返回
五 、Math(java.lang)
概述
final修饰且构造方法为private,故不能有子类且无法实例化,成员方法均为静态方法
常用成员方法
public static double max(double a,double b) //最大值
public static double min(double a,double b)//最小值
public static double abs(double a)//绝对值
public static double random()//返回一个随机数,范围[0,1)
public static double round(double a)//四舍五入,只看小数第一位
public static double pov(double a,double b)//a的b次方
public static double ceil(double a)//向上取整,整数时返回本身
public static double floor(double a)//向下取整,整数时返回本身
六 、基本类型的封装类
(Byte、Character、Boolean、Long、Short、Integer、Float、Double)
用法
- 在集合中只能用封装类型
- 与字符串实现互转 ,如
int a = Integer.parseInt("3");
与基本类型的转换
自动拆箱(装箱):Integer a = 10;int b = a;
七、System
概述:
final修饰,且构造方法为private,故不能有子类不能实例化,该类下所有成员方法为静态方法
public static void exit(int code);//退出JVM,非0参数均为异常终止JVM
public static void gc();//运行垃圾回收器
public static String getProperty(String propertyName);//获取某属性
public static long currentTimeMillis();//获取当前时间距1970...毫秒数