这段程序系统时间怎么取不出来
import java.util.Calendar;
import java.util.GregorianCalendar;
public class TimeDemo {
private Calendar calendar = new GregorianCalendar();
public String getDate()
{
StringBuffer buf= new StringBuffer();
buf.append(calendar.get(Calendar.YEAR)).append("-");
buf.append(calendar.get(Calendar.MONTH)).append("-");
buf.append(calendar.get(Calendar.DAY_OF_MONTH));
return calendar.toString();
}
public static void main(String[] args) {
System.out.println(new TimeDemo().getDate());
}
}
------解决方案-------------------- return calendar.toString();
改成
return buf.toString();
------解决方案--------------------是的。。。new TimeDemo()匿名对象