一、Date --util、
Date date=new Date();
1、this(System.currentTimeMillis())
无参构造方法this()调用本类的有参构造方法
所以输出date默认获得当日期,加了格式
Date date1=new Date();
2、boolean b= date.after(date1);是不是在date1后面
3、boolean b= date.before(date1);是不是在date1前面
4、long time=date..getTime();获得毫秒值,和System一样
二、DateFormat--text、
抽象类 所以实例化子类
DateFormat format=new SimpleDateFormat(//"yyyy-MM-dd-HH:mm:ss");有默认的转换模式
1、String d=format.format(date);把date转成字符串
2、Date pdate=format.parse("2022-01-01 01:01:01");解析,格式一致
3、SimpleDateFormat对象是线程不安全的
三、Calendar、util、
静态
Calendar calendar=Calendar.getInstance();
int a =calendar.get(Calendar.YEAR);获得计算机的当前日历
MONTH DATE HOUR MINUTE SECOND
AM_PM 上午下午
DAY_OF_MONTH 在月的第几天
DAY_OF_WEEK 在周的第几天
DAY_OF_WEEK_IN_MONTH 这一天所在的周是第几周
HOUR_OF_DAY 这一天的第几个小时
int a =calendar.get(Calendar.YEAR)
int a=calender.set(Calendar.DATE,1)设置年月日
calendar.getActualMaximum(Calendar.DAY_OF_MONTH) 取得某月的最后一天
Calendar.getInstance().getTimeInMillis() 从1970年1月1日0时0分0秒到现在的毫秒数
四、Random、util、
Random a=new Ranom();
a.nextInt(10);1—10随机整数,只有int ,long可以放值
a.nextDouble();0——1随机小数
五、Timer、util、
Timer t=new Time();
t.schedule(TimerTask task,3000,1000);
从第三秒开始调用一次text,每隔1秒再调用一次