LocalTime toSecondOfDay() method in Java with Examples
Last Updated :
06 Apr, 2023
The toSecondOfDay() method of LocalTime class is used to return the time as seconds of day from this LocalTime.Value returned by this method lie between 0 to 24 * 60 * 60 – 1.
Syntax:
public int toSecondOfDay()
Parameters: This method accepts no parameters.
Return value: This method returns a long value which is the second of day value and is equivalent to this time.
Below programs illustrate the toSecondOfDay() method:
Program 1:
Java
import java.time.*;
public class GFG {
public static void main(String[] args)
{
LocalTime time
= LocalTime.parse(" 19 : 34 : 50.63 ");
int value = time.toSecondOfDay();
System.out.println("Second of day: "
+ value);
}
}
|
Output:
Second of day: 70490
Program 2:
Java
import java.time.*;
public class GFG {
public static void main(String[] args)
{
LocalTime time
= LocalTime.parse(" 23 : 21 : 45.98 ");
int value = time.toSecondOfDay();
System.out.println("Second of day: "
+ value);
}
}
|
Output:
Second of day: 84105
Reference: https://docs.oracle.com/javase/10/docs/api/java/time/LocalTime.html#toSecondOfDay()
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...