Get the Number of Hours in This Duration in Java



At first, set the Duration −

Duration duration = Duration.ofDays(25);

Now, get the number of hours from the above Duration that has 25 days −

duration.toHours()

Example

 Live Demo

import java.time.Duration;
public class Demo {
   public static void main(String[] args) {
      Duration duration = Duration.ofDays(25);
      System.out.println("Hours in 25 days = "+duration.toHours());
   }
}

Output

Hours in 25 days = 600
Updated on: 2019-07-30T22:30:25+05:30

177 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements