我将 Postgresql 数据库java.sql.Timestamp中的a 作为 Timestamp 数据类型存储,我想找出从数据库中存储的数据库到当前 timestamp 在数分钟或数小时内的差异。这样做的最好方法是什么?有内置的方法吗,还是我必须将其转换为long或其他形式? __
java.sql.Timestamp
我结束使用了此工具,只想将其发布给其他人(如果他们正在搜索)。
public static long compareTwoTimeStamps(java.sql.Timestamp currentTime, java.sql.Timestamp oldTime) { long milliseconds1 = oldTime.getTime(); long milliseconds2 = currentTime.getTime(); long diff = milliseconds2 - milliseconds1; long diffSeconds = diff / 1000; long diffMinutes = diff / (60 * 1000); long diffHours = diff / (60 * 60 * 1000); long diffDays = diff / (24 * 60 * 60 * 1000); return diffMinutes; }