Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to determine session time difference?

 
David A King
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am working on a project that requires calculating the time diff. I get the time stamp
from the mySQL database from a field of type timestamp using:
Date loggedInTime;
loggedInTime = rs.getDate("LoggedIn").getTime();
I must compare the current time with the time above. I get the current time using..
Date currentTime = new java.util.Date();
long now = currentTime.getTime();
I tried subtracting this way (milliseconds):
long diff = now - loggedInTime / 1000;
I get strange results, am I supposed. My end result should be the following;
John Doe logged in at 10:00 AM
The current time is 10:04 AM
His session has been active for [ 4 - minutes ]
Any ideas, algorithms??
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65340
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, this is clearly in the wrong forum, but aren't you missing a few parentheses in your math?
bear
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic