Calendar toString() Method in Java with Examples
The toString() method in Calendar class is used to get the string representation of the Calendar object. This method in Calendar Class is just for debug process and not to be used as an operation.
Syntax:
public String toString()
Parameters: The method does not take any parameters.
Return Value: The method returns the String representation of the Calendar object. It can return an empty object but not null.
Below programs illustrate the working of toString() Method of Calendar class:
Example 1:
// Java Code to illustrate toString() Method import java.util.*; public class CalendarClassDemo { public static void main(String args[]) { // Creating a calendar object Calendar calndr1 = Calendar.getInstance(); // Returning the string representation System.out.println("The string form: " + calndr1.getTime() .toString()); } } |
The string form: Wed Feb 13 09:46:36 UTC 2019
Example 2:
// Java Code to illustrate toString() Method import java.util.*; public class CalendarClassDemo { public static void main(String args[]) { // Creating a calendar object Calendar calndr1 = new GregorianCalendar(2018, 12, 2); // Returning the string representation System.out.println("The string form: " + calndr1.getTime() .toString()); } } |
The string form: Wed Jan 02 00:00:00 UTC 2019
Reference: https://docs.oracle.com/javase/7/docs/api/java/util/Calendar.html#toString()
Recommended Posts:
- Calendar get() method in Java with Examples
- Calendar set() Method in Java with Examples
- Calendar add() Method in Java with Examples
- Calendar getFirstDayOfWeek() Method in Java with Examples
- Calendar setTimeInMillis() Method in Java with Examples
- Calendar setTime() Method in Java with Examples
- Calendar getGreatestMinimum() Method in Java with Examples
- Calendar getInstance() Method in Java with Examples
- Calendar getDisplayNames() Method in Java with Examples
- Calendar clone() Method in Java with Examples
- Calendar clear() Method in Java with Examples
- Calendar setTimeZone() Method in Java with Examples
- Calendar getDisplayName() Method in Java with Examples
- Calendar getLeastMaximum() method in Java with Examples
- Calendar isLenient() 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.


