1. long date=System.currentTimeMillis()
    1. Date date=new Date();//获取当前时间
    2. //date = Mon May 09 09:17:43 CST 2022
    3. System.out.println(date.getTime());
    4. System.out.println(date.getYear()+1900);
    5. System.out.println(date.getMonth()+1);
    6. System.out.println(date.getDate());
    1. var sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    2. System.out.println(sdf.format(date));
    3. //格式化后 输出的是字符串