Java 8 时间戳转换为分钟数 - 代码示例
要将Java 8的时间戳转换为分钟,可以使用以下代码:
import java.time.Instant;
public class Main {
public static void main(String[] args) {
long timestamp = 1621620000;
// 将时间戳转换为Instant对象
Instant instant = Instant.ofEpochSecond(timestamp);
// 获取分钟数
long minutes = instant.getEpochSecond() / 60;
System.out.println(minutes);
}
}
在这个例子中,我们将时间戳1621620000转换为Instant对象,然后通过调用getEpochSecond()方法获取秒数,并将其除以60得到分钟数。
输出结果为27027000,表示时间戳1621620000对应的分钟数为27027000分钟。
原文地址: https://www.cveoy.top/t/topic/fTCv 著作权归作者所有。请勿转载和采集!