LocalTime toString() method in Java with Examples
The toString() method of LocalTime class is used to represents this time as a String, such as 20:15:34.111.
Following ISO-8601 formats are used for representation:
- HH:mm
- HH:mm:ss
- HH:mm:ss.SSS
- HH:mm:ss.SSSSSS
- HH:mm:ss.SSSSSSSSS
This method is derived from the Object Class and behaves in a similar way.
Syntax:
public String toString()
Parameters: This method accepts no parameter.
Return value: This method returns a String representation of this LocalTime.
Below programs illustrate the toString() method:
Program 1:
// Java program to demonstrate // LocalTime.toString() 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"); // print LocalTime System.out.println("LocalTime : " + time.toString()); } } |
LocalTime : 19:34:50.630
Program 2:
// Java program to demonstrate // LocalTime.toString() method import java.time.*; public class GFG { public static void main(String[] args) { // create a LocalTime object LocalTime time = LocalTime.parse("01:00:01"); // print LocalTime System.out.println("Old LocalTime: " + time.toString()); // add 600 Minutes using plusMinutes() LocalTime value = time.plusMinutes(600); // print result System.out.println("New LocalTime: " + value.toString()); } } |
Old LocalTime: 01:00:01 New LocalTime: 11:00:01
References: https://docs.oracle.com/javase/10/docs/api/java/time/LocalTime.html#toString()
Recommended Posts:
- LocalTime with() Method in Java with Examples
- LocalTime until() Method in Java with Examples
- LocalTime from() method in Java with Examples
- LocalTime plus() method in Java with Examples
- LocalTime get() method in Java with Examples
- LocalTime minusMinutes() method in Java with Examples
- LocalTime range() method in Java with Examples
- LocalTime adjustInto() method in Java with Examples
- LocalTime minusNanos() method in Java with Examples
- LocalTime atDate() method in Java with Examples
- LocalTime atOffset() method in Java with Examples
- LocalTime ofSecondOfDay() method in Java with Examples
- LocalTime minusHours() method in Java with Examples
- LocalTime ofInstant() method in Java with Examples
- LocalTime ofNanoOfDay() 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.



