_Ritchie

Java中的Unix时间转换

一、普通日期转换为Unix时间戳

SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println(format.parse("2015-01-01 00:00:01").getTime()/1000);

二、Unix时间戳转换为普通日期

Long timestamp = Long.parseLong("1420041600")*1000;
String date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(timestamp));

posted on 2015-10-17 10:46  _Ritchie  阅读(736)  评论(0)    收藏  举报

导航