尝试将Unix timstamp从数据库转换为日期格式的String时.
int _startTS = evtResult.getInt("start"); //outputs 1345867200
Long _sLong = new Long(_startTS); //outputs 1345867200
//I've also tried: Long _sLong = new Long(_startTS*1000); //outputs 1542436352
DateTime _startDate = new DateTime(_sLong); //outputs 1970-01-16T08:51:07.200-05:00
Run Code Online (Sandbox Code Playgroud)
时间戳是:Sat, 25 Aug 2012.我不知道为什么1970年总是输出,所以希望有人可以看到我正在犯的一个愚蠢的错误.
Mad*_*mer 59
Unix时间以秒为单位,Java时间为毫秒
你需要将其倍增1000倍
DateTime _startDate = new DateTime(_sLong * 1000L);
Run Code Online (Sandbox Code Playgroud)
您可能要检查这个答案了
Unix时间戳是一些SECONDS以来的1970-01-01 00:00:00.
DateTime(long instant)构造函数需要多少个MILLISECONDS.
long _startTS = ((long) evtResult.getInt( "start" )) * 1000;
DateTime _startDate = new DateTime( _startTS );
Run Code Online (Sandbox Code Playgroud)
编辑:或者使用你的getLong(..)方法evtResult来避免强制转换.
| 归档时间: |
|
| 查看次数: |
27660 次 |
| 最近记录: |