gpt4 book ai didi

java - 如何设置毫秒格式

转载 作者:行者123 更新时间:2023-12-01 09:12:40 24 4
gpt4 key购买 nike

在我的代码中,我使用

获取毫秒数
// elaspsed time in milliseconds
public long getElapsedTime() {
if (running) {
return System.currentTimeMillis() - startTime;
}
return stopTime - startTime;
}

只要是一个整数我想获取 00.0000 格式的毫秒不过到目前为止我已经尝试过了

return ((System.currentTimeMillis() - startTime) / 1000f);

但我没有达到特定的格式

最佳答案

您无法将返回类型设置为 long 并返回 doubleString 值。

但是,如果您需要将毫秒值格式化为提供的格式,您应该能够使用以下代码片段来完成。

String.format("%d.%d",  TimeUnit.MILLISECONDS.toSeconds(millies),millies%1000);

关于java - 如何设置毫秒格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40822392/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com