要比较两个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时间戳的大小。