Click here to watch in Youtube :
https://www.youtube.com/watch?v=4l6NIQyW_So&list=UUhwKlOVR041tngjerWxVccw
Click the below Image to Enlarge
![]() |
Java Tutorial: System class in java [How to measure the time interval] |
import java.io.IOException;
public class TimeDemo
{
public static void main(String[] args) throws IOException
{
/*
* Returns the current value of the system timer, in
* nanoseconds
*/
System.out.print("time in nanoseconds = ");
System.out.println(System.nanoTime());
/*
* Returns the current value of the system timer, in
* milliseconds
*/
System.out.print("time in milliseconds = ");
System.out.println(System.currentTimeMillis());
}
}
Outputtime in nanoseconds = 8765309144714
time in milliseconds = 1488772824057
TimeDiffDemo.javapublic class TimeDiffDemo
{
public static void main(String[] args) throws InterruptedException
{
long startTime = System.currentTimeMillis();
int i = 1;
while (i < 1000)
{
Thread.sleep(10);
++i;
}
long endTime = System.currentTimeMillis();
long timeDiff = endTime - startTime;
System.out.println("timeDiff in ms = " + timeDiff);
}
OutputtimeDiff in ms = 10428
Click the below link to download the code:
No comments:
Post a Comment