常用类
1.Date
Date d=new Date();
System.out.println(d);
System.out.println(d);//返回1970年1月1号到现在的毫秒数
System.out.println(d.getTime());//获取当前时间
System.out.println(d.getHours());//获取当前分钟
System.out.println(d.getMinutes());//获取秒
System.out.println(d.getSeconds());
2.SimpleDateFormat
时间格式化类
[准备知识:yyyy-MM-dd hh:mm:ss] 年月日 时分秒
//1-新建一个SimpleDateFormat对象,并设置参数为你自己想要的格式
SimpleDateFormat sim=new SimpleDateFormat("yyyy/MM/dd");
String currentTime=sim.format(d);
System.out.println(currentTime);
浙公网安备 33010602011771号