# Java Program to Convert Hour to Microsecond and Microsecond to Hour

In the previous article, we have discussed about Java Program to Convert Hour to Millisecond and Millisecond to Hour

In this article we will see how to convert Hour to Microsecond and Microsecond to Hour by using Java programming language.

## Java Program to Convert Hour to Microsecond and Microsecond to Hour

Before jumping into the program let’s know the relationship between Hour and Microsecond and how we can convert Hour to Microsecond and vice versa.

Hour and Microsecond are used as unit of time.

1 Hour =3.6e+9 Microsecond
1 Microsecond =  2.7778e-10 Hour

Formula to convert Microsecond to Hour.

Hour = Millisecond / 3.6e+9

Formula to convert Hour to Microsecond.

Millisecond= Hour * 3.6e+9

Let’s see different ways to convert Hour to Microsecond and Microsecond to Hour.

### Method-1: Java Program to Convert Hour to Microsecond and Microsecond to Hour By Using Static Input Value

Approach:

• Declare Hour and Microsecond value.
• Then convert Hour to Microsecond and Microsecond to Hour by using the formula.
• Print result.

Program:

import java.util.*;
public class Main
{
public static void main(String args[])
{
//Scanner class object created
Scanner sc=new Scanner(System.in);
//value of hour declared
double hour = 1;
//value of microsecond declared
double microsecond = 1;

//converting hour to microsecond
double us = hour * 3.6e+9;
//converting microsecond to hour
double hr = microsecond / 3.6e+9;
//printing result
System.out.println("Value of "+hour+" hour in microsecond: "+ us);
System.out.println("Value of "+microsecond+" microsecond in hour: "+ hr);
}
}
Output:

Value of 1.0 hour in microsecond: 3.6E9
Value of 1.0 microsecond in hour: 2.7777777777777777E-10


### Method-2: Java Program to Convert Hour to Microsecond and Microsecond to Hour By Using User Input Value

Approach:

• Take user input of Hour and Microsecond value.
• Then convert Hour to Microsecond and Microsecond to Hour by using the formula.
• Print result.

Program:

import java.util.*;
public class Main
{
public static void main(String args[])
{
//Scanner class object created
Scanner sc=new Scanner(System.in);
//Taking the value input of double variable hour
System.out.println("Enter value of hour: ");
double hour = sc.nextDouble();
//Taking the value input of double variable microsecond
System.out.println("Enter value of microsecond: ");
double microsecond = sc.nextDouble();

//converting hour to microsecond
double us = hour * 3.6e+9;
//converting microsecond to hour
double hr = microsecond / 3.6e+9;
//printing result
System.out.println("Value of "+hour+" hour in microsecond: "+ us);
System.out.println("Value of "+microsecond+" microsecond in hour: "+ hr);
}
}
Output:

Enter value of hour:
2
Enter value of microsecond:
8000000
Value of 2.0 hour in microsecond: 7.2E9
Value of 8000000.0 microsecond in hour: 0.0022222222222222222


### Method-3: Java Program to Convert Hour to Microsecond and Microsecond to Hour By Using User Defined Method

Approach:

• Take user input of Hour and Microsecond value.
• Call a user defined method by passing Hour and Microsecond value as parameter.
• Inside method convert Hour to Microsecond and Microsecond to Hour by using the formula.
• Print result.

Program:

import java.util.*;
public class Main
{
public static void main(String args[])
{
//Scanner class object created
Scanner sc=new Scanner(System.in);
//Taking the value input of double variable hour
System.out.println("Enter value of hour: ");
double hour = sc.nextDouble();
//Taking the value input of double variable microsecond
System.out.println("Enter value of microsecond: ");
double microsecond = sc.nextDouble();
//calling user defined method convert()
convert(hour, microsecond);
}

//convert() method to convert microsecond to hour and vice versa
public static void convert(double hour, double microsecond)
{
//converting hour to microsecond
double us = hour * 3.6e+9;
//converting microsecond to hour
double hr = microsecond / 3.6e+9;
//printing result
System.out.println("Value of "+hour+" hour in microsecond: "+ us);
System.out.println("Value of "+microsecond+" microsecond in hour: "+ hr);
}
}
Output:

Enter value of hour:
4
Enter value of microsecond:
75000000
Value of 4.0 hour in microsecond: 1.44E10
Value of 7.5E7 microsecond in hour: 0.020833333333333332


The best and excellent way to learn a java programming language is by practicing Simple Java Program Examples as it includes basic to advanced levels of concepts.

Related Java Programs: