要比较两个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时间戳的大小。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:如何比较两个java毫秒时间戳的大小