简体   繁体   English

登录注销系统时间仍然相同

[英]Login Logout System Time is still the Same

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. 自从我使用JFrame logoutTime该程序以来,这就是变量logoutTimeloginTime的来源。

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) (请检查图片)

as you see, I log in at 2019/02/24 13:38:36 but when I log out three minutes later, it's still the same 如您所见,我于2019/02/24 13:38:36登录,但三分钟后退出登录,仍然保持不变

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. 如果要在按注销时获取当前时间,则应使用新时间重置logoutTime变量的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM