取当前时间
public static void main(String[] args) throws SQLException, ParseException{
// TODO Auto-generated method stub
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
String d1;
d1=df.format(new Date());
System.out.println(d1);// new Date()为获取当前系统时间
System.out.println(df.format(new Date()));// new Date()为获取当前系统时间
}
jdbc 日期格式插入:
PreparedStatement psmt = conn.prepareStatement(sql);
psmt.setTimestamp(4,Timestamp.valueOf(person1.getAddDate()) );
pstmt.setTimestamp(4, new Timestamp(System.currentTimeMillis()));
或者:
pstmt.setTimestamp(4, new Timestamp(new java.util.Date().getTime()));