测试转换方法:
import java.text.SimpleDateFormat;
import java.util.Date;
public class Student {
private int id;
private String sno;
private String sname;
private java.util.Date birthday;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getSno() {
return sno;
}
public void setSno(String sno) {
this.sno = sno;
}
public String getSname() {
return sname;
}
public void setSname(String sname) {
this.sname = sname;
}
public Date getBirthday() {
return birthday;
}
public void setBirthday(Date birthday) {
this.birthday = birthday;
}
public static void main(String[] args) {
java.sql.Date d1=new java.sql.Date(System.currentTimeMillis());
java.util.Date d2 = new java.util.Date(d1.getTime());
Student stu = new Student();
stu.setBirthday(d2);
SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
System.out.println(fmt.format(d2));
}
}