- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
LocalTime toNanoOfDay() method in Java
The time in the form of nanoseconds of the day can be obtained using the toNanoOfDay() method in the LocalTime class in Java. This method requires no parameters and it returns the time in the form of nanoseconds of the day.
A program that demonstrates this is given as follows −
Example
import java.time.*; public class Main { public static void main(String[] args) { LocalTime lt = LocalTime.parse("05:15:30"); System.out.println("The LocalTime is: " + lt); System.out.println("The nanoseconds of the day are: " + lt.toNanoOfDay()); } }
Output
The LocalTime is: 05:15:30 The nanoseconds of the day are: 18930000000000
Now let us understand the above program.
First the LocalTime is displayed. Then the time in the form of nanoseconds of the day is obtained using the toNanoOfDay() method. A code snippet that demonstrates this is as follows −
LocalTime lt = LocalTime.parse("05:15:30"); System.out.println("The LocalTime is: " + lt); System.out.println("The nanoseconds of the day are: " + lt.toNanoOfDay());
Advertisements