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();
立即学习“Java免费学习笔记(深入)”;
String t = String.valueOf(ct);
其实上面的String t就相当于 ct+"";
知识转为字符串格式
public String refFormatNowDate(){
Date nowTime = new Date(System.currentTimeMillis());
SimpleDateFormat sdFormatter = new SimpleDateFormat("yyy-MM-dd");
String retStrFormatNowDate = sdFormatter.format(nowTime);
return retStrFormatNowDate;
}
以上就是JAVA获取当前系统事件的实例方法的详细内容,更多请关注php中文网其它相关文章!
java怎么学习?java怎么入门?java在哪学?java怎么学才快?不用担心,这里为大家提供了java速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号