我在action中使用
String date=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Calendar.getInstance().getTime());
得到系统时间,数据库中表的类型为datetime型,怎么能吧date转换成Date型??
在线等待解答..............

解决方案 »

  1.   

    程序操作数据库datetime类型一般最好对应到java中timestamp类型
    Date datetime=new Timestamp(System.currenttimemillis());如果一定要把字符串转成Date类型就要去切割字符串先用空格切割为日期和时间在把日期用“-”切割为年,月,日 ,时间用":"切割为时,分,秒。最后在用这些信息去构造一个Date,貌似已经南辕北辙了
      

  2.   

    DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");        
    Date date = null;   
    String sDate=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Calendar.getInstance().getTime());              
    date = format.parse(sDate);  可能要捕捉一下异常
      

  3.   

    Date date = new Date();
    //new Date(Calendar.getInstance().getTime());
    //new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2008-08-08 08:00:00");