java.util.Date time conversion error is java.sql.Date

Used in mysql the date type, java java.sql.Date is corresponding to the type, but requires generating java.sql.Date java.util.Date conversion types, found in the process of the conversion error occurred, on both sides of inconsistencies

       SimpleDateFormat sdf =new SimpleDateFormat("yyyy-mm-dd");
        Date stDate=sdf.parse(sDate);                 //入住日期
        java.sql.Date startDate=new java.sql.Date(stDate.getTime());
        Date enDate=sdf.parse(eDate);                  //离开日期
        java.sql.Date endDate=new java.sql.Date(enDate.getTime());
       System.out.println(sDate);

Console output:
Here Insert Picture Description
This error is actually not a big mistake, the date format "mm" represents the seconds, the month use the "MM":

       SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd");
        System.out.println("string:"+sDate);
        Date stDate=sdf.parse(sDate);                 //入住日期
        System.out.println("util.Date:"+stDate);
        java.sql.Date startDate=new java.sql.Date(stDate.getTime());
        System.out.println("sql.Date:"+startDate);
        Date enDate=sdf.parse(eDate);                  //离开日期
        java.sql.Date endDate=new java.sql.Date(enDate.getTime());

So no problem.
Here Insert Picture Description

Guess you like

Origin blog.csdn.net/sinat_40770656/article/details/90676538