我想将Calendar输出转换为String。以下是我的代码
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.
这里getTime()方法的输出是'Date'类型,所以得到错误。 有没有办法进行类型转换或任何解决方案?
答案 0 :(得分:1)
请参阅:
Calendar cal=Calendar.getInstance();
System.out.println("Time is "+cal.getTime());
String str=cal.toString();
System.out.println("Time is "+str);