Alex Rivera | Logout

Java time since the epoch

Asked 2012-08-08T18:46:50.680
16

In Java, how can I print out the time since the epoch given in seconds and nanoseconds in the following format :

java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");

My input is:

long mnSeconds;
long mnNanoseconds;

Where the total of the two is the elapsed time since the epoch 1970-01-01 00:00:00.0.

Edit
Report

1 Answer

27

Use this and divide by 1000

long epoch = System.currentTimeMillis();

System.out.println("Epoch : " + (epoch / 1000));
answered 2012-08-08T18:53:14.697

Your Answer