Java 常用类总结

Math类:
    基本的数学计算
    向上向下取整
    random方法
    Random类封装了随机数
System类:
    标准输出输入错误流
    获取当前时间的毫秒值
    获取系统属性集合 Properties,这是一个Map集合。
    也可以给系统设置属性信息,其他程序也可以使用。
Runtime类:
    每一个Java程序都有其Runtime实例,使程序可以和系统相连接。
    Runtime是一个单例的类
    有趣的方法:
        exec
Date类:
    注意:
        年:y-1900
        月:0-12
        日:1-31
    构造方法:
        Date date = new Date();
        Date date = new Date(毫秒值);
        date 英文格式的封装值
    日期对象和毫秒值之间的转换:
        毫秒值---日期对象
            1:Date构造方法
            2:使用Date的setTime方法
        日期对象---毫秒值
            Date的getTime方法
    方法介绍:    
        after  befer   判断日期是否是指定日期的前后
        compare        期比较

Calendar抽象类类:
    构造:
        Calendar c = Calendar.getInstance();重载可以传入时区等
    获取年月日:
        get方法:
        int year = c.get(Calendar.YEAR);
        int month= c.get(Calendar.MONTH)+1;    0--11
        int day= c.get(Calendar.DAY);
            DAY_OF_MONTH  DAY_OF_WEEK WEEK_OF_MONTH     
            等等。
    为日历设置日期:
        set方法:
        void c.set(int year, int month, int date)
    日期偏移:
        add方法:
        add(int field, int amount) ;给定的日历字段添加或减去指定的时间量。
        field:DAY_OF_MONTH    WEEK_OF_MONTH 等    
        amount:可以是正数(向前偏移),负数(向后偏移)

DateFormat抽象类:
    格式化实例问题:
        getInstance()
        getDateInstance()
        getTimeInstance()
        getDateTimeInstance()
        及重载方法。重载方法可以指定格式化风格。
    格式化日期为String:
        Date date = new Date();
        DateFormat dateFormat = DateFormat.getDateInstance();
        String dateString = dateFormat.format(date);
        2017-2-5
    格式化日期时间为String:
        DateFormat dateFormat = DateFormat.getDateTimeInstance();
        2017-2-5 12:45:20
    格式化风格问题:
        getDateInstance()方法有其重载的方法
            getDateInstance(int style)
            getDateInstance(int style, Locale aLocale)
        
        getDateTimeInstance()方法有其重载的方法
            getDateTimeInstance(int dateStyle, int timeStyle)
            getDateTimeInstance(int dateStyle, int timeStyle, Locale aLocale)
    
        style参数为DateFormat抽象类定义的常量:
            DateFormat.LONG
            DateFormat.FULL
            DateFormat.MEDIUM等
        自定义风格:
            使用子类SimpleDateFormat格式化
            参数格式可以在文档中查到。
            DateFormat DateFormat = new SimpleDateFormat(yyyy--MM--dd);
    解析时期时间:
        使用Date parse(String date)方法。
            传入date字符串形式,返回Date对象。
            Date date = dateFromat.parse(String date);
        解析非默认格式:
            只需要使用对应风格的DateFormat。LONG,FULL等
        解析自定义格式
             使用SimpleDateFormat类
            




原文地址:https://www.cnblogs.com/Xmingzi/p/6635859.html