5、日期的大小比较、日期的加减。
1. 当前日期
System.currentTimeMillis();
等同于:
Date date = new Date();
data.getTime()
2. 格式化转换:文本-时间 互转
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
sdf.parse()
sdf.format()
3. 日期中年、月、日、时、分、秒、星期、月份等获取
Date date = new Date();
Calendar now5= Calendar.getInstance();
now5.setTime(date);
System.out.println("获取年:" + now5.get(Calendar.YEAR));
System.out.println("获取月(月份是从0开始的):" + now5.get(Calendar.MONTH));
System.out.println("获取日:" + now5.get(Calendar.DAY_OF_MONTH));
System.out.println("获取时:" + now5.get(Calendar.HOUR));
System.out.println("获取分:" + now5.get(Calendar.MINUTE));
System.out.println("获取秒:" + now5.get(Calendar.SECOND));
System.out.println("获取上午、下午:" + now5.get(Calendar.AM_PM));
System.out.println("获取星期数值(星期是从周日开始的):" + now5.get(Calendar.DAY_OF_WEEK));
//指定时间
Calendar now5= Calendar.getInstance();
now5.set(2018,,.....)