1.【日期类 Date】
// 创建对象 直接调用引用名就可以获取时间
Date date = new Date(); System.out.println(date);
// 1.getTime() 获取时间(毫秒值) 时间戳,获取1970.1.1至今的毫秒数 // 2.setTime() 设置时间(毫秒值)
3.格式化时期 SimpleDateFormat
SimpleDateFormat sd = new SimpleDateFormat("yyyy/MM/dd");
// 4.转变日期格式format(date),返回类型是String
// 5.String 转String 格式需要相同 parse(strDate) 括号里的模板需要跟字符串格式同步
如果格式不相同 抛出ParseException
2.
1.日历类 Calendar是抽象类 不能直接new对象 通过Calendar.getInstance()
Calendar now = Calendar.getInstance();
// 2.now.set(年,月,日) 设置日期 月份 0-11月
/ 3.now.getActualMaximum() 获取括号里的最大的值
// 4.now.get(Calendar.YEAR) 获取年
// 5.now.get(Calendar.MONTH)+1)获取月份 从0开始所以要+1
// 6.now.get(Calendar.DATE) 获取天数
// 7.获取小时 (12小时)now.get(Calendar.HOUR)
// 8.获取小时(24小时)now.get(Calendar.HOUR_OF_DAY)
// 9.获取分钟 now.get(Calendar.MINUTE)
// 10.获取秒 now.get(Calendar.SECOND)
// 11.获取星期now.get(Calendar.DAY_OF_WEEK)//1代表星期日,2代表星期一
// 12. 在。。。之后 c1.after(c2) 返回的是布尔类型
// 13.在。。。之前 c1.before(c2)返回的是布尔类型
3.
// 【Calendar的子类:GregorianCalendar】
GregorianCalendar g1 = new GregorianCalendar(); // 1.判断是否为闰年isLeapYear(2000) // 2.获取毫秒数getTimeInMillis()