java中如何得到系统当前时间年月日(简单实用方式)

//得到long类型当前时间
long l = System.currentTimeMillis();
//new日期对象
Date date = new Date(l);
//转换提日期输出格式
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

   String nyr = dateFormat.format(date);

System.out.println(nyr);

注意:"yyyy-MM-dd HH:mm:ss"这个根式不是固定的根据你的需要自己的调整;

猜你喜欢

转载自blog.csdn.net/zty1317313805/article/details/80778695