I need to find elapsed time in milliseconds by comparing current time in timestamp with created timestamp in java
For example
Updated Timestamp from DB column : 26/07/20 12:00:19.330000000 PM
Current Timestamp : 26/07/20 11:55:19.330000000 AM
Timeout configured 2 mins
To get current timestamp,
public static Timestamp getTimestampinGMT(Date date) {
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
df.setTimeZone(TimeZone.getTimeZone("GMT"));
String strCurrentTimeInGMT = df.format(date);
return Timestamp.valueOf(strCurrentTimeInGMT);
}
And I'm converting updated timestamp column from DB to millisecond
Timestamp.valueOf(createtime).getTime()
Timeout configured 2 mins is converted to millsec,
TimeUnit.MINUTES.toMillis(2);
Is there any best way to compare timestamp and calculate the elapsed time?