日期格式化
public static void main(String[] args) { Date nowtime = new Date(); System.out.println(nowtime);//Wed May 22 08:48:56 CST 2019 //引入格式化日期 //Date---->String SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss SSS"); //开始格式化(Date ---->String) String s = sdf.format(nowtime); System.out.println(s); } //获取特定的日期 public static void main(String[] args) throws ParseException { String time = "2008-08-09 08:08:08 008"; //将String转化为Date SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SSS"); //格式不能随便写 Date d = sdf.parse(time); System.out.println(d);//Sat Aug 09 08:08:08 CST 2008 } public static void main(String[] args) { Date d1 = new Date(10000000);//是毫秒数 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SSS"); System.out.println(sdf.format(d1)); //获取当前系统前十分钟时间 Date d2 = new Date(System.currentTimeMillis()-1000*60*10); System.out.println(sdf.format(d2)); }