我有两个时间戳:
Timestamp loggedintime=rs.getTimestamp("LOGIN_TIME");
Timestamp loggedouttime=rs.getTimestamp("LOGOUT_TIME");
现在,我想要做的是找到这两个时间戳之间的间隔,如15分钟或1小时10分钟等。
但我不知道如何做到这一点。所以请帮助我
答案 0 :(得分:0)
你走了,
Timestamp loggedintime=rs.getTimestamp("LOGIN_TIME");
Timestamp loggedouttime=rs.getTimestamp("LOGOUT_TIME");
long interval = loggedouttime.getTime() - loggedintime.getTime();
//total hours
long hours = interval / (60 * 60 * 1000);
//time period that should be represented in minutes
long minutes = (interval % (60 * 60 * 1000)) / (60 * 1000);
//time period that should be represented in seconds
long seconds = (interval % (60 * 1000)) / 1000;
System.out.println(hours + " hours " + minutes + " min " + seconds + " sec");
注意:请注意间隔时间不准确,因为不考虑小于一秒(<1000)的毫秒
答案 1 :(得分:0)
答案 2 :(得分:0)
long login=System.currentTimeMillis();
.
.
.
long logout=System.currentTimeMillis();
long difInSeconds=(logout-login)/1000;
long hours=difInSeconds/3600;
long minutes=difInSeconds%3600;
long seconds=difInSeconds-(hours*3600+minutes*60);