system.currenttimemillis()产生一个当前的毫秒,这个毫秒其实就是自1970年1月1日0时起的毫秒数,date()其实就是相当于date(system.currenttimemillis()),因为date类还有构造date(longdate),用来计算long秒与1970年1月1日之间的毫秒差。
得到了这个毫秒数,我们自己也可以算起现在的年月日周时,但是这不是我们去计算的,因为有Calendar.Calendar最终结出的结果就是年月日周时时区。
System.currentTimeMillis()获得的是自1970-01-01 00:00:00.000到当前时刻的时间距离,类型为long
String.valueOf(System.currentTimeMillis())这个语句可转为一下的格式:
long ct = System.currentTimeMillis();
String t = String.valueOf(ct);
其实上面的String t就相当于 ct+"";
知识转为字符串格式
public String refFormatNowDate(){
使用 Husky 将 pre-commit、pre-push 和 commit-msg 检查集成到仓库中,以便代理和开发人员在更改离开工作站之前运行相同的本地防护措施。
Date nowTime = new Date(System.currentTimeMillis());
SimpleDateFormat sdFormatter = new SimpleDateFormat("yyy-MM-dd");
String retStrFormatNowDate = sdFormatter.format(nowTime);
return retStrFormatNowDate;
}
Java免费学习笔记:立即使用
解锁 Java 大师之旅:从入门到精通的终极指南










