我正在使用以下代码计算特定用户的非 Activity 间隔:
inActiveInterval = System.currentTimeMillis() - objHttpSession.getLastAccessTime();
如果 session 有昨天的时间,这会给出上次访问时间的正确差异吗?
最佳答案
是的,这是正确的。根据HttpSession.getLastAccessedTime()
的API :
Returns the last time [...] as the number of milliseconds since midnight January 1, 1970 GMT
与System.currentTimeMillis()
一致:
Returns: the difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC.
您还可以使用:
new Date().getTime()
作为Date.getTime()
具有相同的含义:
Returns: the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this date.
关于java - System.currentTimeMillis() 会有日期的详细信息吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9108788/