要比較兩個Java時間戳的大小,可以使用比較運算符(例如“>”、“<”、“==”)或者使用Java提供的比較方法。
下面是一些示例代碼:
long timestamp1 = System.currentTimeMillis();
long timestamp2 = System.currentTimeMillis() - 1000;
if (timestamp1 > timestamp2) {
System.out.println("timestamp1 is greater than timestamp2");
} else if (timestamp1 < timestamp2) {
System.out.println("timestamp1 is smaller than timestamp2");
} else {
System.out.println("timestamp1 is equal to timestamp2");
}
long timestamp1 = System.currentTimeMillis();
long timestamp2 = System.currentTimeMillis() - 1000;
if (Long.compare(timestamp1, timestamp2) > 0) {
System.out.println("timestamp1 is greater than timestamp2");
} else if (Long.compare(timestamp1, timestamp2) < 0) {
System.out.println("timestamp1 is smaller than timestamp2");
} else {
System.out.println("timestamp1 is equal to timestamp2");
}
這兩種方法都可以幫助您比較兩個Java時間戳的大小。