Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
Java Program to convert this duration to the total length in nanoseconds
With this, get the nanoseconds in days, hours and minutes. At first, set the Duration:
Duration d1 = Duration.ofDays(5); Duration d2 = Duration.ofHours(20); Duration d3 = Duration.ofMinutes(15);
Convert the above Duration to nanoseconds:
System.out.println("Nanoseconds in 5 days = "+d1.toNanos());
System.out.println("Nanoseconds in 20 hours = "+d2.toNanos());
System.out.println("Nanoseconds in 15 minutes = "+d3.toNanos());
Example
import java.time.Duration;
public class Demo {
public static void main(String[] args) {
Duration d1 = Duration.ofDays(5);
Duration d2 = Duration.ofHours(20);
Duration d3 = Duration.ofMinutes(15);
System.out.println("Nanoseconds in 5 days = "+d1.toNanos());
System.out.println("Nanoseconds in 20 hours = "+d2.toNanos());
System.out.println("Nanoseconds in 15 minutes = "+d3.toNanos());
}
}
Output
Nanoseconds in 5 days = 432000000000000 Nanoseconds in 20 hours = 72000000000000 Nanoseconds in 15 minutes = 900000000000
Advertisements
