1 public static void main(String[] args) {
2
3 String time = System.currentTimeMillis();//获取当前时间精确到毫秒级的时间戳,例:1525849325942
4
5 System.out.println(timeStamp2Date(time))
6
7 }
8
9 public static String timeStamp2Date(String time) {
10 Long timeLong = Long.parseLong(time);
11 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//要转换的时间格式
12 Date date;
13 try {
14 date = sdf.parse(sdf.format(timeLong));
15 return sdf.format(date);
16 } catch (ParseException e) {
17 e.printStackTrace();
18 return null;
19 }
20 }