Convert Calendar to String
12,413
Please refer:
Calendar cal=Calendar.getInstance();
System.out.println("Time is "+cal.getTime());
String str=cal.toString();
System.out.println("Time is "+str);
Author by
Toothless
Updated on June 04, 2022Comments
-
Toothless almost 2 years
I want to convert Calendar output to String. The following is my code
Calendar cal=Calendar.getInstance(); System.out.println("Time is "+cal.getTime()); String str=cal.getTime(); //This is how I want to store the output, but this is wrong.
Here the output of the getTime() method is of 'Date' type, so getting error. Is there any way to typecast or any solution?
-
Prashant about 8 years
String str = cal.getTime().toString()
-