Converting Epoch time to date string

nexus490 picture nexus490 · Mar 18, 2012 · Viewed 87.8k times · Source

I have seen this question asked multiple times and none of the answers seem to be what i need.

I have a long type variable which has an epoch time stored in it.

What i want to do is convert it to a String

for example if the epoch time stored was for today the final string would read:

17/03/2012

How would i to this?

Answer

Reinard picture Reinard · Mar 18, 2012

Look into SimpleDateFormat

SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
sdf.format(new Date(myTimeAsLong));