使用java代码将时间戳和时间互相转换

时间戳转时间:

SimpleDateFormat simpleDateFormat = null;

simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
Date date = new Date(System.currentTimeMillis());
String day = simpleDateFormat.format(date);
simpleDateFormat = new SimpleDateFormat("HHmmss");  
String time
= simpleDateFormat1.format(date);

时间转时间戳

SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = simpleDateFormat.parse(s);
long ts = date.getTime();

 

posted @ 2018-10-11 19:36  做个读书人  阅读(16066)  评论(1编辑  收藏  举报