TangoStar
TangoStar

Reputation: 551

Having an exact difference value between two Date value

I want to do somthing like this:

    Date startDate = new Date();
 // Do Something
    Date endDate = new Date();
    double msElapsedTime =endDate.getTime()-startDate.getTime();

I have the result value in milisecond like this:7.0 but I want to have the exaxt value for example:7.15

How can I do that?

Upvotes: 2

Views: 93

Answers (1)

anubhava
anubhava

Reputation: 784968

Using System.nanoTime():

long startTime = System.nanoTime()
// Do Something
long endTime = System.nanoTime();
// to get microsecond value
double msElapsedTime = ((double) (endTime - startTime)) / 1000.0;

Upvotes: 2

Related Questions