public class CalendarDemo01 {
public static void main(String[] args) throws Exception {
Calendar cal = Calendar.getInstance();
StringBuffer buf = new StringBuffer();
buf.append(cal.get(Calendar.YEAR)).append("-");
buf.append(cal.get(Calendar.MONTH) + 1).append("-");
buf.append(cal.get(Calendar.DAY_OF_MONTH)).append(" ");
buf.append(cal.get(Calendar.HOUR_OF_DAY)).append(":");
buf.append(cal.get(Calendar.MINUTE)).append(":");
buf.append(cal.get(Calendar.SECOND));
System.out.println(buf);
}
}
![](https://i-blog.csdnimg.cn/blog_migrate/000531c42a564c1b3dd2316c10d5d270.png)