I am trying to create a date object(format : HH:MM) from a String Example 13:30(HH:MM). I want to save the HH:MM in MySql table but the below code enters some random value in the column (eg: '6828-00-00 00:00:00'). How can i store the date value in Mysql in the HH:MM format ?
Date date = null;
String afternoon = "13" +":" +"30";
String time = afternoon;
try {
date = new SimpleDateFormat("HH:mm").parse(time);
}
catch (ParseException e) {
e.printStackTrace();
}
long d = date.getTime();
java.sql.Date sqlDate = new java.sql.Date(d);
String sql3 = "CREATE TABLE IF NOT EXISTS DateTime"+
"(UniqueBusID VARCHAR(255) not NULL, " +
" Timenings DATETIME DEFAULT NULL ,"+
" PRIMARY KEY ( UniqueBusID ))";
stmt.executeUpdate(sql3);
stmt.executeUpdate("INSERT INTO DateTime " + "VALUES ('Test3','"+sqlDate.getTime()+"')");