System.currentTimeMillis()的作用是返回当前的计算机时间,格式为当前计算机时间和GMT时间(格林威治时间)1970年1月1号0时0分0秒所差的毫秒数
比如在做项目时,需要统计下gc操作的执行的消耗时间
除此之外,还可以获取当前的系统时间
//直接把这个方法强制转换成date类型
Date nowTime = new Date(System.currentTimeMillis());
//设定显示格式
SimpleDateFormat sdFormatter = new SimpleDateFormat("yyyy-MM-dd");
//按指定格式转换
String now = sdFormatter.format(nowTime);
System.out.println(now);
以及用当前毫秒数给文件命名等
File f = new File("c:\\"+System.currentTimeMillis() + "");
f.createNewFile();