Converting Unix timestamp to String with Joda Time

java, jodatime

Solution

Unix time is in seconds, Java time is milliseconds

You'll need to multiple it by 1000

DateTime _startDate = new DateTime(_sLong * 1000L);

You may want to check this answer out

Problem

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 ``` 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.

Original source

Related problems