当尝试将 Unix 时间戳从数据库转换为日期格式的字符串时。
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
时间戳适用于:2012 年 8 月 25 日星期六
。我不知道为什么 1970 总是输出所以希望有人能看到我犯的一个愚蠢的错误。
最佳答案
Unix 时间以秒为单位,Java 时间以毫秒为单位
你需要将它乘以 1000
DateTime _startDate = new DateTime(_sLong * 1000L);
您可能想查看 answer出去
关于java - 使用 Joda Time 将 Unix 时间戳转换为字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12031333/