- 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 ofNanoOfDay() method in Java
A LocalTime object can be obtained using the nanoseconds of the day with the ofNanoOfDay() method in the LocalTime class in Java. This method requires a single parameter i.e. the nanoseconds of the day and it returns the LocalTime object for the nanoseconds of the day
A program that demonstrates this is given as follows
Example
import java.time.*; public class Demo { public static void main(String[] args){ long nanoSeconds = 1000000000; System.out.println("The nanoseconds of the day: " + nanoSeconds); System.out.println("The LocalTime is: " + LocalTime.ofNanoOfDay(nanoSeconds)); } }
output
The nanoseconds of the day: 1000000000 The LocalTime is: 00:00:01
Now let us understand the above program.
First the nanoseconds of the day are displayed. Then the LocalTime object is obtained using the nanoseconds of the day with the ofNanoOfDay() method and printed. A code snippet that demonstrates this is as follows:
long nanoSeconds = 1000000000; System.out.println("The nanoseconds of the day: " + nanoSeconds); System.out.println("The LocalTime is: " + LocalTime.ofNanoOfDay(nanoSeconds));
Advertisements