- 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 ofSecondOfDay() method in Java
A LocalTime object can be obtained using the seconds of the day with the ofSecondOfDay() method in the LocalTime class in Java. This method requires a single parameter i.e. the seconds of the day and it returns the LocalTime object for the seconds 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 seconds = 18930; System.out.println("The seconds of the day: " + seconds); System.out.println("The LocalTime is: " + LocalTime.ofSecondOfDay(seconds)); } }
output
The seconds of the day: 18930 The LocalTime is: 05:15:30
Now let us understand the above program.
First the seconds of the day are displayed. Then the LocalTime object is obtained using the seconds of the day with the ofSecondOfDay() method and printed. A code snippet that demonstrates this is as follows:
long seconds = 18930; System.out.println("The seconds of the day: " + seconds); System.out.println("The LocalTime is: " + LocalTime.ofSecondOfDay(seconds));
Advertisements