java - System.currentTimeMillis() 会有日期的详细信息吗?

标签 java session servlets

我正在使用以下代码计算特定用户的非 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/

相关文章:

java - 添加TextView时出现空指针异常

java - 在shiro中,哪个更好地为用户分配多个权限或多个角色?

java - JSch session 超时限制

java - 提供服务器中生成并存储在内存中的 zip 文件

Java EE - 更改 index.jsp 的目录

java - TableView 使用哪种数据结构不允许重复项?

java - 在 Java 中生成字符串标记

javascript - 使用ajax在浏览器中单击返回时销毁php session

java - 如何通过 session 检查新用户的 servlet?

java - 引用 root 的 Tomcat servlet 相对路径