I am trying to make a submit button that saves the user input when it is clicked and I am having a problem with the if condition part. What I want to happen is when the user clicked the button after 10:00 o'clock (based on system time) the Report on database would be "Late" else report would be "Not Late". But every time I clicked the button even the system time is before 10:00 it always says "Late". How to fix this?
Code:
try {
String sql = "INSERT INTO studentregisterlogin" + "(SSN, TimeIn, TimeOut, Report)" + "VALUES (?,?,?,?)";
con = DriverManager.getConnection("jdbc:mysql://localhost/studentlogin", "root", "");
pst = con.prepareStatement(sql);
pst.setString(1, tfSerialNumber.getText());
pst.setTimestamp(2, new Timestamp(System.currentTimeMillis()));
pst.setString(3, " ");
// My Problem is this Condition
SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm");
Date date = new Date(System.currentTimeMillis());
try {
if (date.after(dateFormat.parse("10:00"))) {
pst.setString(4, "Late");
} else if (date.before(dateFormat.parse("10:00"))){
pst.setString(4, "NotLate");
}
} catch (ParseException ex) {
Logger.getLogger(Menu.class.getName()).log(Level.SEVERE, null, ex);
}
pst.executeUpdate();
//updateTable();
} catch (SQLException | HeadlessException ex) {
JOptionPane.showMessageDialog(null, ex);
}