java如何检查时间戳是否为10分钟?
我有一个时间戳(searchTimestamp)
,我需要检查它是否少于10分钟
long currentTimestamp = System.currentTimeMillis();
long searchTimestamp = getTheTimestampFromURL();// this also gives me back timestamp in 13 digit (1425506040493)
long difference = Math.abs(currentTimestamp - searchTimestamp);
System.out.println(difference);
if (difference > 10 * 60 * 1000) {
System.out.println("timestamp is greater than 5 minutes old");
}
我有上面的代码,这是工作良好。这是正确的方法还是有更好的方法
注意:
getTheTimestampFromURL
将始终早于当前时间戳(以毫秒为单位)
# 1 楼答案
我要说的是搜索时间戳>;currentTimestamp所以你不需要abs,只需要使用searchTimestamp-currentTimestamp