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

 Live Demo

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());
Updated on: 2019-07-30T22:30:25+05:30

85 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements