我是Java的新手。我正在尝试将人类格式时间转换为纪元时间。我对很多网站进行了审核,下面提到了每一个步骤,但我的输出结果不对。
String format = "dd/MM/yyyy HH:mm:ss";
DateFormat dateFormat = new SimpleDateFormat(format);
String expDate=dateFormat.format(new Date(1478017281));
System.out.println(expDate);
系统输出:
18/01/1970 08:03:37
预期输出:
01/11/2016 21:51:21
先谢谢。
答案 0 :(得分:4)
Date构造函数采用一个长参数,该参数应该是以毫秒为单位的时间,而不是秒。在它的末尾添加3 0&#39,它将打印预期的结果。