How to set time to epoch time java?

android, date, epoch, java, time

Solution

use new Date(0L);

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd-HH:mm:ss");
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
System.out.println(sdf.format(new Date(0L)));

Take care of your timezone cause it will change depends on what you have by default.

UPDATE In java 8 you can use the new `java.time` library

You have this constant `Instant.EPOCH`

Problem

I'm trying to set the time to epoch date time in java. how can I do this? so that I could get year months days etc out of the epoch date time.

Original source

Related problems