我正在尝试编写Java代码作为我的项目的一部分来获取进程的当前时间,然后我需要为它添加一个固定的超时时间。这个新时间必须与我上面的时间进行比较,并据此作出决定。我无法为当前时间增加时间并进行比较。任何人都可以通过建议方式来帮助我吗?时间戳计算函数
这是我的代码:
public class SessionDetails
{
public String getCurrentUtcTimestamp() {
TimeZone timeZone = TimeZone.getTimeZone("UTC:00");
DateFormat dateFormat = DateFormat.getDateTimeInstance();
dateFormat.setTimeZone(timeZone);
timeStamp = dateFormat.format(new Date());
return timeStamp;
}
public void createSession()
{
int value = getsession();
String timeStamp = getCurrentUtcTimestamp() ;
System.out.println("New session Details :");
System.out.println("session value:" + value);
System.out.println("Time of creation :" + timeStamp);
}
public boolean checkTimeout(int value)
{
private static long c_Timeout = 10000;
String currentTime = getCurrentUtcTimestamp() ;
if (currentTime > timeStamp + c_Timeout) //failing to implement this logic efficiently .please do suggest a way.Thanku..
System.out.println("Sorry TimeOut");
else
System.out.println("Welcome");
}
}