获取时间戳及转化为yyyyMMdd格式的时间


1、获取当前时间戳两种方法:
 System.currentTimeMillis();  #1536764057392  微秒
 new Date().getTime();  #1536764057392  微秒
2、时间戳转化为yyyyMMdd格式时间
SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd HH:mm:ss");
String date_1 = df.format(System.currentTimeMillis()); # 20180912 22:54:17
String date_2 = df.format(new Date().getTime()); # 20180912 22:54:17
3、yyyyMMdd HH:mm:ss 格式时间转化为时间戳
String date_1 = "20180910 22:58:10";
SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd HH:mm:ss");
System.out.println(String.valueOf(df.parse(date_1).getTime())); #1536591490000  微秒


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM