Reputation: 491
Hi i'm getting a dates and hours in timestamp format from a webservice and i'm trying to convert them in String to show them in my app
i've tried
Timestamp ts = new Timestamp(jsonObject.getLong("release_date"));
or
SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy");
Date date = new Date( jsonObject.getLong("release_date"));
and it always give me "1970-01-17 07:54:39.6" even if i get other timestamp
for example both 1407279600 and 1406674800 give me "1970-01-17"
any idea on how to do it ?
Upvotes: 0
Views: 953
Reputation: 1500615
It sounds like your timestamp format is probably in seconds since the Unix epoch, instead of the milliseconds that Java expects - so just multiply it by 1000:
Date date = new Date(jsonObject.getLong("release_date") * 1000L);
You should also think about what time zone you're interested in, and set that on your SimpleDateFormat
.
Upvotes: 3