JavaHow to Convert Second to Microseconds in Java

How to Convert Second to Microseconds in Java

There are some instances where a developer may need to convert seconds into smaller fractions of time – such as a microsecond. In the example code below, we show programmers how to convert seconds to microseconds using Java and the TimeUnit enum:

*/

import java.util.concurrent.*;

public class ConvertingToMicroseconds
{
	public static void main(String args[])
	{
		ConvertingToMicroseconds ConvertingToMicroseconds = new ConvertingToMicroseconds();
		ConvertingToMicroseconds.proceed();
		
	}
	
	private void proceed()
	{
		System.out.println("1 second(s) --> " + TimeUnit.MICROSECONDS.convert(1L, TimeUnit.SECONDS) + " microsecond(s)");
		
	}
}

/*

You can expect the following output when you run this Java code:

[[email protected]]# java ConvertingToMicroseconds
1 second(s) --> 1000000 microsecond(s)

Read: Java Quick Tip: List All Files in a Directory by Type

Latest Posts

Related Stories