在Java中使用日历API时性能不佳

在Java中使用日历API时性能不佳,java,Java,以下代码的性能非常差。 我知道日历API存在性能问题 long startInMilliSec = measFileCreationTime_OssTime; Calendar thisMoment = Calendar.getInstance(); long currentInMilliSec = thisMoment.getTime().getTime(); if (currentInMilliSec >= startInMilliSec) { return (true);

以下代码的性能非常差。 我知道日历API存在性能问题

long startInMilliSec = measFileCreationTime_OssTime;
Calendar thisMoment = Calendar.getInstance();
long currentInMilliSec = thisMoment.getTime().getTime();

if (currentInMilliSec >= startInMilliSec) {
    return (true);
} else {
    return (false);
}

有其他方法吗?

您可以使用
System.currentTimeMillis()
获取自1970年12月1日以来的当前时间(毫秒)。减去两个毫秒值可以得到它们之间的持续时间(以毫秒为单位)。日历只需要在解释如此毫数值的年、月等时使用


如果您想要更精确,那么可以使用
System.nanoTime()
来获得纳米精度。在这种情况下,绝对纳米值没有特殊意义,只能用于计算随后获取的纳米值之间的时间差。

您可以使用
System.currentTimeMillis()
获取自1970年12月1日以来的当前时间(毫秒)。减去两个毫秒值可以得到它们之间的持续时间(以毫秒为单位)。日历只需要在解释如此毫数值的年、月等时使用


如果您想要更精确,那么可以使用
System.nanoTime()
来获得纳米精度。在这种情况下,绝对纳米值没有特殊意义,只能用于计算随后获取的纳米值之间的时间差。

和更短/更简单的数值。日历/公历日历是您可能使用的最粗的对象之一。;)而且更短/更简单。日历/公历日历是您可能使用的最粗的对象之一。;)