Mr.Noob Mr.Noob - 1 year ago 79
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.

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download