LocalTime toSecondOfDay() method in Java with Examples
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 the long value which is the second of day value and is equivalent to this time.
Below programs illustrate the toSecondOfDay() method:
Program 1:
// Java program to demonstrate // LocalTime.toSecondOfDay() method import java.time.*; public class GFG { public static void main(String[] args) { // create a LocalTime object LocalTime time = LocalTime.parse( "19:34:50.63" ); // extract second of day from toSecondOfDay() int value = time.toSecondOfDay(); // print result System.out.println( "Second of day: " + value); } } |
Second of day: 70490
Program 2:
// Java program to demonstrate // LocalTime.toSecondOfDay() method import java.time.*; public class GFG { public static void main(String[] args) { // create a LocalTime object LocalTime time = LocalTime.parse( "23:21:45.98" ); // extract Second of day from toSecondOfDay() int value = time.toSecondOfDay(); // print result System.out.println( "Second of day: " + value); } } |
Second of day: 84105
Reference: https://docs.oracle.com/javase/10/docs/api/java/time/LocalTime.html#toSecondOfDay()
Recommended Posts:
- LocalTime get() method in Java with Examples
- LocalTime plus() method in Java with Examples
- LocalTime with() Method in Java with Examples
- LocalTime from() method in Java with Examples
- LocalTime until() Method in Java with Examples
- LocalTime plusSeconds() method in Java with Examples
- LocalTime withMinute() method in Java with Examples
- LocalTime withNano() method in Java with Examples
- LocalTime truncatedTo() method in Java with Examples
- LocalTime compareTo() method in Java with Examples
- LocalTime range() method in Java with Examples
- LocalTime adjustInto() method in Java with Examples
- LocalTime withSecond() method in Java with Examples
- LocalTime atDate() method in Java with Examples
- LocalTime atOffset() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.