Good day! I have a problem regarding to this system. Everytime I press log out button, time that I log in is there instead of the current time.
String logout = usernameTF.getText();
if (logout.contains(name))
{
usernameTF.setText("");
timeouttf.setText(dtf.format(logoutTime));
sessiontimetf.setText(Integer.toString((int) Duration.between(loginTime, logoutTime).getSeconds()));
username.clear();
loginbtn.setEnabled(true);
resetbtn.setEnabled(true);
}
else
{
usernameTF.setText("");
JOptionPane.showMessageDialog(null, "WRONG INFORMATION", "ERROR", JOptionPane.ERROR_MESSAGE);
}
Please help me with this. I tried other solutions but it didn't work.
This is the origin of the variables logoutTime
and loginTime
since I made this program with JFrame.
private static final DateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
private static final DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
LocalDateTime loginTime = LocalDateTime.now();
LocalDateTime logoutTime = LocalDateTime.now();
this is the result when I try to log in and out. (please check out the picture)
since you haven't provided the whole code, i can only guess that what
timeouttf.setText(dtf.format(logoutTime));
this line does is take the stored time in predefined variable and set it as log out time.
If you want to get current time when you press logout then you should reset the value of logoutTime variable with the new time.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.