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:

[root@mypc]# java ConvertingToMicroseconds
1 second(s) --> 1000000 microsecond(s)

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

Get the Free Newsletter!
Subscribe to Developer Insider for top news, trends & analysis
This email address is invalid.
Get the Free Newsletter!
Subscribe to Developer Insider for top news, trends & analysis
This email address is invalid.

Latest Posts

Related Stories