Java Convert Number of Days to Hours
Tags: Java Duration Java 8
In this Java core tutorial we learn how to convert number of days to number of hours in Java programming language.
How to convert number of days to hours in Java
In Java, with a number of days we can use the java.time.Duration class to convert it to number of hours as the following Java code.
ConvertDaysToHoursExample1.java
import java.time.Duration;
public class ConvertDaysToHoursExample1 {
public static void main(String... args) {
long numberOfDays = 365;
// Convert number of days to hours
Duration duration = Duration.ofDays(numberOfDays);
long numberOfHours = duration.toHours();
System.out.println("Number of days: " + numberOfDays);
System.out.println("Number of hours: " + numberOfHours);
}
}
Number of days: 365
Number of hours: 8760
Happy Coding 😊
Related Articles
Java Convert Number of Days to Minutes