Java:epoch日期为MM / DD / YYYY

时间:2014-03-11 12:59:35

标签: java date simpledateformat epoch

我的时间:1386696238

我的代码:

Date date = new Date(Long.parseLong(currentNotification.getDate_created()));
        SimpleDateFormat formatter = new SimpleDateFormat("MM/DD/yyyy", Locale.getDefault());
        String dateString = formatter.format(date);

我的结果:1/16/1970

期望的结果:12/10/2013

我做错了什么?

2 个答案:

答案 0 :(得分:6)

您的值以秒为单位,因此您需要将其乘以1000.

此外,DD是一年中的某一天,您需要dd

SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy", Locale.getDefault());

答案 1 :(得分:4)

我想你应该将输入乘以1000(以秒为单位的UNIX时间戳,但以毫秒为单位的Java j.u.Date)。

编辑:

哦代码中的另一个错误:模式符号应为d,而不是D(日期)。