使用Joda Time将Unix时间戳转换为String [英] Converting Unix timestamp to String with Joda Time
本文介绍了使用Joda Time将Unix时间戳转换为String的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
尝试将Unix timstamp从数据库转换为日期格式的String。
When trying to convert a Unix timstamp, from a database, to a String in a date format.
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年总是输出,所以希望有人能看到我正在犯的一个愚蠢的错误。
The timestamp is for: Sat, 25 Aug 2012
. I have no idea why 1970 is always the output so hopefully someone can see a stupid mistake I'm making.
推荐答案
Unix时间以秒为单位,Java时间为毫秒
Unix time is in seconds, Java time is milliseconds
您需要将其倍增1000
You'll need to multiple it by 1000
DateTime _startDate = new DateTime(_sLong * 1000L);
您可能需要查看 answer out
You may want to check this answer out
这篇关于使用Joda Time将Unix时间戳转换为String的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文