
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 toSecondOfDay() method in Java
The time in the form of seconds of the day can be obtained using the toSecondOfDay() method in the LocalTime class in Java. This method requires no parameters and it returns the time in the form of seconds 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 seconds of the day are: " + lt.toSecondOfDay()); } }
Output
The LocalTime is: 05:15:30 The seconds of the day are: 18930
Now let us understand the above program.
First the LocalTime is displayed. Then the time in the form of seconds of the day is obtained using the toSecondOfDay() 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 seconds of the day are: " + lt.toSecondOfDay());
Advertisements