【发布时间】:2014-08-24 20:03:36
【问题描述】:
我正在尝试使用 SimpleDateFormat 进行简单的历元到日期转换。每当我运行程序时,我都会不断收到转换后的无效日期。我已经在转换器中运行了时代标记[并且我还将日期存储在外部服务器中],所以我知道输出应该是什么,但我仍然收到错误的转换。我在实验中尝试了对 long epochTime 的多项数学更改,但无济于事。我确实知道 [或至少我很确定] 我的纪元时间戳以毫秒为单位存储,因此需要 * 1000 更改。这是我所拥有的:
String convertedTime = null;
//(1) //startTime = startTime/1000; --none of these three manipulations solve the issue
//(2) //startTime = startTime * 1000;
//(3) //long change = (long) startTime * 1000;
Date d = newDate(startTime); //startTime is *long* parameter passed into method
SimpleDateFormat formatter = new SimpleDateFormat("mm-dd-yyyy 'at' hh:mm:ss");
convertedTime= formatter.format(d);
例如,如果纪元标记是 1404327407738 并且我不包括 (1)、(2)、(3) 我在 01:56 收到 56-02-2014:下午 47 点
- 包括 (1) - 05-17-1970 上午 12:05:27
- 包括 (2) - 05:35:38 AM 35-13-46471
- 包括 (3) - 上午 05:35:38 的 35-13-46471(是的,我在此处替换了 startTime 的更改)
我应该收到 07-02-2014 下午 01:56:47
【问题讨论】:
标签: java date simpledateformat epoch