Date date =new java.text.SimpleDateFormat( "yyyy-MM-dd HH:mm ").parse( "2008-11-14 15:20 ");
-----------------------------------------------------------------------------------------------------------
String str = "2008-11-14 ";
public static final DateFormat formatter = new SimpleDateFormat( "yyyy-MM-dd ");
public boolean valid(String str){
try{
Date date = (Date)formatter.parse(str);
return str.equals(formatter.format(date));
}catch(Exception e){
return false;
}
}
--------------------------------------------------------------------------------------------------------
将一个时间录入String tm="1999-12-22"(时间)转换成Date型(java.sql.Date不是java.util.Date)
然后在保存到SQL的datetime型time字段里!
SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd" );
String aa="1999-12-22";
java.util.Date timeDate = null;
try {
timeDate = sdf.parse(aa);
} catch (ParseException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}//util类型
java.sql.Date dateTime = new java.sql.Date(timeDate.getTime());//sql类型