Calendar cal=Calendar.getInstance();
Date date=cal.getTime();
(2) Date转化为Calendar
Date date=new Date();
Calendar cal=Calendar.getInstance();
cal.setTime(date);
(3)、字符串格式化时间
String strDate = "2010-10-10";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
sdf.format(sdf.parse(strDate));
(4)、设置时间格式化时间
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
cal.set(Calendar.YEAR, 2009);
cal.set(Calendar.MONTH,5);
cal.set(Calendar.DATE,20);
// cal.set(2009,6,20);和上面设置等同
System.out.println(sdf.format(cal.getTime()));
3、得到年月日
Calendar cal = Calendar.getInstance();
cal.get(Calendar.YEAR);/MONTH/DATE
注意月份要+1
java.util.date和java.sql.date转换
java.util.Date u_date = new java.util.Date();
java.sql.Date s_date = new java.sql.Date(u_date.getTime());
System.out.println("util:"+u_date);
System.out.println("util转sql:"+ new java.sql.Date(u_date.getTime()));
System.out.println("sql:"+s_date);
System.out.println("sql转util:"+new java.util.Date(s_date.getTime()));