Mr.Noob Mr.Noob - 2 months ago 11
Java Question

How to set time to epoch time java?

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.


use new Date(0L);

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd-HH:mm:ss");
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