当前位置: 首页 > 工具软件 > mod-groovy > 使用案例 >

java groovy 动态计算_计算Java / Groovy中的经过时间

阳建弼
2023-12-01

您可以使用除法和mod进行所有这些操作。

long l1 = start.getTime();

long l2 = stop.getTime();

long diff = l2 - l1;

long secondInMillis = 1000;

long minuteInMillis = secondInMillis * 60;

long hourInMillis = minuteInMillis * 60;

long dayInMillis = hourInMillis * 24;

long elapsedDays = diff / dayInMillis;

diff = diff % dayInMillis;

long elapsedHours = diff / hourInMillis;

diff = diff % hourInMillis;

long elapsedMinutes = diff / minuteInMillis;

diff = diff % minuteInMillis;

long elapsedSeconds = diff / secondInMillis;

那应该给您您要求的所有信息。

编辑:由于人们似乎很困惑,不,这不会考虑leap年或夏令时切换等问题。这是纯粹的消逝时间,这就是打开要求的时间。

 类似资料: