将时间存储在变量中

时间:2014-12-24 15:04:09

标签: java netbeans

在我的查询中,我想将当前系统时间存储在b变量中,以便我可以将该变量与另一个时间进行比较,以执行以下条件。请帮助我编写代码..

        ResultSet rs=stmt.executeQuery(sql);

        String user=txtid.getText();
        String pwd=new String (passwordfld.getPassword());
        int loop=0;
        while(rs.next())
        {
            String uname=rs.getString("Emp_ID");
            String password=rs.getString("Password");
            if ((user.equals(uname)) && (pwd.equals(password)))
            {
                st.executeUpdate("insert into Attendance (Emp_ID,Date,Time_in) Values ('"+user+"',curdate(),curtime());");


                s.executeUpdate("update Attendance set Late='Yes' where emp_id='"+user+"' and date=curdate() and time_in>'23:15:00';");
                s.executeUpdate("update Attendance set Late='No' where emp_id='"+user+"' and date=curdate() and time_in<'23:15:00';");


                Time b=new Time();


                if (b>08:40:00)
                {
                   s.executeUpdate("update Attendance set Late='Yes' where emp_id='"+user+"' and date=curdate();");
                   JOptionPane.showMessageDialog(null, "OOps You are late..!!");
                 }
                else
                {
                   s.executeUpdate("update Attendance set Late='No' where emp_id='"+user+"' and date=curdate();");
                }

                JOptionPane.showMessageDialog(null, "HAve a niCe daY");
                dispose();
                new Home().setVisible(true);
                loop++;
            }
        }
        rs.close();
        if (loop==0) {
            JOptionPane.showMessageDialog(null, "Username and Password not in database!");
        }
    }
    catch (Exception e)
    {
        JOptionPane.showMessageDialog(null,e);
}                                 

1 个答案:

答案 0 :(得分:1)

您可以尝试以下方式:

Calendar c = Calendar.getInstance();
if (c.get(Calendar.HOUR_OF_DAY) >= 8 && c.get(Calendar.MINUTE) >= 40) {//if you want 8PM then replace 8 with 20.
  System.out.println("Hello time now is greater than 8:40AM");
}