我正在嘗試編寫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");
}
}