打印当前时间。学习使用Date类和Calendar类。
“`
package test1;
import java.util.*;
public class Date {
public static void main(String[] args) {
// TODO Auto-generated method stub
//Date nowTime=new Date();
// System.out.println(nowTime);
Calendar calendar=Calendar.getInstance();
int year=calendar.get(Calendar.YEAR);
int month =calendar.get(Calendar.MONTH)+1;
int day=calendar.get(Calendar.DAY_OF_MONTH);
int hour=calendar.get(Calendar.HOUR_OF_DAY);
int minute=calendar.get(Calendar.MINUTE);
int second=calendar.get(Calendar.SECOND);
System.out.println("现在的时间是:");
System.out.println(""+year+"年"+month+"月"+day+"日");
System.out.println(""+hour+"时"+minute+"分"+second+"秒");
}
}
`“