- TimeUnit Class in Java with Examples
- Java
- Java
- Convert hour to minute java
- Learn Latest Tutorials
- Preparation
- Trending Technologies
- B.Tech / MCA
- Javatpoint Services
- Training For College Campus
- Java Convert Number of Hours to Minutes
- How to convert number of hours to minutes in Java
- Java Program to Convert Minute to Hour and Hour to Minute
- Java Program to Convert Minute to Hour and Hour to Minute
- Method-1: Java Program to Convert Minute to Hour and Hour to Minute By Using Static Input Value
- Method-2: Java Program to Convert Minute to Hour and Hour to Minute By Using User Input Value
- Method-3: Java Program to Convert Minute to Hour and Hour to Minute By Using User Defined Method
- Java Program to Convert Minute to Hour and Hour to Minute
- Java Program to Convert Minute to Hour and Hour to Minute
- Method-1: Java Program to Convert Minute to Hour and Hour to Minute By Using Static Input Value
- Method-2: Java Program to Convert Minute to Hour and Hour to Minute By Using User Input Value
- Method-3: Java Program to Convert Minute to Hour and Hour to Minute By Using User Defined Method
TimeUnit Class in Java with Examples
TimeUnit is an Enum available in java.util.concurrent package. TimeUnit as the name implies deals with Time units. TimeUnit provides time representation at a given unit of granularity. It makes available methods to convert time across time units. TimeUnit is useful to know how a given time should be interpreted that is which time unit should be considered. Minute differences between time durations such as in microseconds and nanoseconds can be figured out using TimeUnit. It is used to perform timing and delay operations.
It supports nanoseconds, microseconds, milliseconds, seconds, minutes, hours, and days units. For these units, TimeUnit specifies corresponding enum constants:
- Nanoseconds: One thousandth of a microsecond
- Microseconds: One thousandth of a millisecond
- Milliseconds: One thousandth of a second
- Seconds: One second
- Minutes: Sixty seconds
- Hours: Sixty minutes
- Days: Twenty four hours
Java
System.out.println(hours + » Hours line number17 index16 alt2″> + » Days line number18 index17 alt1″> + » Minutes» );
96 Hours = 4 Days = 5760 Minutes 5760 Minutes = 345600000000 Microseconds 345600000000 Microseconds = 345600 Seconds TimeUnit object type: MINUTES
Java
TimeUnit Example Now, thread will run for 5 seconds NANOSECONDS : 86400000000000 MICROSECONDS : 86400000000 MILLISECONDS : 86400000 SECONDS : 86400 Thread Execution Paused Resuming Thread Execution. MINUTES : 1440 HOURS : 24 DAYS : 1
Utility methods available in TimeUnit:
Methods | Description |
---|---|
long convert() | Converts the time duration inputted with its unit to the required unit. |
long toDays() | Converts the time duration to Days. |
long toHours() | Converts the time duration to Hours. |
long toMicros() | Converts the time duration to Microseconds. |
long toMillis() | Converts the time duration to Milliseconds. |
long toMinutes() | Converts the time duration to Minutes. |
long toNanos() | Converts the time duration to Nanoseconds. |
long toSeconds() | Converts the time duration to Seconds. |
static TimeUnit valueOf() | Returns the enum constant of the type with the specified name. |
static TimeUnit [] values() | Returns an array containing the enum constants. |
void sleep() | Performs a Thread.sleep using this time unit. Pause for given TimeUnit. |
void timedWait() | Performs a timed Object.wait using this time unit. Wait for the given time unit to execute. |
void timedJoin() | Performs a timed Thread.join using this time unit. Thread is provided to do work for a given time duration only. |
Convert hour to minute java
Learn Latest Tutorials
Preparation
Trending Technologies
B.Tech / MCA
Javatpoint Services
JavaTpoint offers too many high quality services. Mail us on h[email protected], to get more information about given services.
- Website Designing
- Website Development
- Java Development
- PHP Development
- WordPress
- Graphic Designing
- Logo
- Digital Marketing
- On Page and Off Page SEO
- PPC
- Content Development
- Corporate Training
- Classroom and Online Training
- Data Entry
Training For College Campus
JavaTpoint offers college campus training on Core Java, Advance Java, .Net, Android, Hadoop, PHP, Web Technology and Python. Please mail your requirement at [email protected].
Duration: 1 week to 2 week
Like/Subscribe us for latest updates or newsletter
Java Convert Number of Hours to Minutes
In this Java core tutorial we learn how to convert a number of hours to minutes value using the java.time.Duration class in Java programming language.
How to convert number of hours to minutes in Java
In Java, with a given number of hours we can use the Duration.toMinutes() to convert it to minutes value as the following Java code.
import java.time.Duration; public class ConvertHoursToMinutesExample public static void main(String. args) long numberOfHours = 3; // Convert Number of Hours to Minutes long numberOfMinutes = Duration.ofHours(numberOfHours).toMinutes(); System.out.println("Number of hours: " + numberOfHours); System.out.println("Number of minutes: " + numberOfMinutes); > >
Number of hours: 3 Number of minutes: 180
Java Program to Convert Minute to Hour and Hour to Minute
In this article we will see how to convert Minute to Hour and Hour to Minute by using Java programming language.
Java Program to Convert Minute to Hour and Hour to Minute
Before jumping into the program let’s know the relationship between Minute and Hour and how we can convert Minute to Hour and vice versa.
Minute and Hour are used as unit of time.
1 Hour = 60 Minute 1 Minute = 0.0166667 Hour
Formula to convert Minute to Hour.
Formula to convert Hour to Minute.
Let’s see different ways to convert Minute to Hour and Hour to Minute.
Method-1: Java Program to Convert Minute to Hour and Hour to Minute By Using Static Input Value
- Declare Minute and Hour value.
- Then convert Minute to Hour and Hour to Minute by using the formula.
- Print result.
import java.util.*; public class Main < public static void main(String args[]) < //Scanner class object created Scanner sc=new Scanner(System.in); //value of minute declared double minute = 1; //value of hour declared double hour = 1; //converting minute to hour double hr = minute/60; //converting hour to minute double min = hour*60; //printing result System.out.println("Value of "+minute+" minute in hour: "+ hr); System.out.println("Value of "+hour+" hour in minute: "+ min); >>
Output: Value of 1.0 minute in hour: 0.016666666666666666 Value of 1.0 hour in minute: 60.0
Method-2: Java Program to Convert Minute to Hour and Hour to Minute By Using User Input Value
- Take user input of Minute and Hour value.
- Then convert Minute to Hour and Hour to Minute by using the formula.
- Print result.
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 minute System.out.println("Enter value of minute: "); double minute = sc.nextDouble(); //Taking the value input of double variable hour System.out.println("Enter value of hour: "); double hour = sc.nextDouble(); //converting minute to hour double hr = minute/60; //converting hour to minute double min = hour*60; //printing result System.out.println("Value of "+minute+" minute in hour: "+ hr); System.out.println("Value of "+hour+" hour in minute: "+ min); >>
Output: Enter value of minute: 180 Enter value of hour: 2 Value of 180.0 minute in hour: 3.0 Value of 2.0 hour in minute: 120.0
Method-3: Java Program to Convert Minute to Hour and Hour to Minute By Using User Defined Method
- Take user input of Minute and Hour value.
- Call a user defined method by passing Minute and Hour value as parameter.
- Inside method convert Minute to Hour and Hour to Minute by using the formula.
- Print result.
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 minute System.out.println("Enter value of minute: "); double minute = sc.nextDouble(); //Taking the value input of double variable hour System.out.println("Enter value of hour: "); double hour = sc.nextDouble(); //calling user defined method convert() convert(minute, hour); >//convert() method to convert minute to hour and vice versa public static void convert(double minute, double hour) < //converting minute to hour double hr = minute/60; //converting hour to minute double min = hour*60; //printing result System.out.println("Value of "+minute+" minute in hour: "+ hr); System.out.println("Value of "+hour+" hour in minute: "+ min); >>
Output: Enter value of minute: 120 Enter value of hour: 5 Value of 120.0 minute in hour: 2.0 Value of 5.0 hour in minute: 300.0
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:
Java Program to Convert Minute to Hour and Hour to Minute
In this article we will see how to convert Minute to Hour and Hour to Minute by using Java programming language.
Java Program to Convert Minute to Hour and Hour to Minute
Before jumping into the program let’s know the relationship between Minute and Hour and how we can convert Minute to Hour and vice versa.
Minute and Hour are used as unit of time.
1 Hour = 60 Minute 1 Minute = 0.0166667 Hour
Formula to convert Minute to Hour.
Formula to convert Hour to Minute.
Let’s see different ways to convert Minute to Hour and Hour to Minute.
Method-1: Java Program to Convert Minute to Hour and Hour to Minute By Using Static Input Value
- Declare Minute and Hour value.
- Then convert Minute to Hour and Hour to Minute by using the formula.
- Print result.
import java.util.*; public class Main < public static void main(String args[]) < //Scanner class object created Scanner sc=new Scanner(System.in); //value of minute declared double minute = 1; //value of hour declared double hour = 1; //converting minute to hour double hr = minute/60; //converting hour to minute double min = hour*60; //printing result System.out.println("Value of "+minute+" minute in hour: "+ hr); System.out.println("Value of "+hour+" hour in minute: "+ min); >>
Output: Value of 1.0 minute in hour: 0.016666666666666666 Value of 1.0 hour in minute: 60.0
Method-2: Java Program to Convert Minute to Hour and Hour to Minute By Using User Input Value
- Take user input of Minute and Hour value.
- Then convert Minute to Hour and Hour to Minute by using the formula.
- Print result.
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 minute System.out.println("Enter value of minute: "); double minute = sc.nextDouble(); //Taking the value input of double variable hour System.out.println("Enter value of hour: "); double hour = sc.nextDouble(); //converting minute to hour double hr = minute/60; //converting hour to minute double min = hour*60; //printing result System.out.println("Value of "+minute+" minute in hour: "+ hr); System.out.println("Value of "+hour+" hour in minute: "+ min); >>
Output: Enter value of minute: 180 Enter value of hour: 2 Value of 180.0 minute in hour: 3.0 Value of 2.0 hour in minute: 120.0
Method-3: Java Program to Convert Minute to Hour and Hour to Minute By Using User Defined Method
- Take user input of Minute and Hour value.
- Call a user defined method by passing Minute and Hour value as parameter.
- Inside method convert Minute to Hour and Hour to Minute by using the formula.
- Print result.
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 minute System.out.println("Enter value of minute: "); double minute = sc.nextDouble(); //Taking the value input of double variable hour System.out.println("Enter value of hour: "); double hour = sc.nextDouble(); //calling user defined method convert() convert(minute, hour); >//convert() method to convert minute to hour and vice versa public static void convert(double minute, double hour) < //converting minute to hour double hr = minute/60; //converting hour to minute double min = hour*60; //printing result System.out.println("Value of "+minute+" minute in hour: "+ hr); System.out.println("Value of "+hour+" hour in minute: "+ min); >>
Output: Enter value of minute: 120 Enter value of hour: 5 Value of 120.0 minute in hour: 2.0 Value of 5.0 hour in minute: 300.0
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: