Adding hours, minutes, seconds to SQL Date

前端 未结 4 1760
南旧
南旧 2020-12-10 10:00

Good Day!

I have a problem with SQL Dates. I think the main problem is on the perspective of time. In my program, I have a start and end date, say for example

4条回答
  •  独厮守ぢ
    2020-12-10 10:26

    This is the code for timestamp datatype

    Date d=new Date();
    Timestamp t=new Timestamp(d.getTime());try{
    PreparedStatement pt=con.prepareStatement("INSERT INTO survey_schedule (start_date) VALUES (?);");
    pt.setTimestamp(1, start_date);
    
    pt.executeUpdate();}
    catch(Exception e)
    {
        System.out.println(e);
    }
    

    This is an example that will store the date and time in the mysql database

提交回复
热议问题