时间转换

2019-10-25  本文已影响0人  咯噔ya

Java默认获取时间戳是13位,精确到毫秒:System.currentTimeMillis()


1.时间 转 时间戳(10位)(2019-10-25 16:48:25转1571991938)

SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

long time=sdf.parse(时间).getTime()/1000;

2.时间戳(10位) 转 时间(1571991938 转 2019-10-25 16:48:25)

SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

String time=sdf.format(时间戳*1000)

3.在Jdk8中,针对统计时间等场景。推荐使用Instant类。

上一篇 下一篇

猜你喜欢

热点阅读