我正在做一个倒数计时器,我摆脱了int变量并制作了long。以下方法如何获得小时、分钟和秒。
public static long getHours(long totalSeconds) {
return (long) Math.floor(totalSeconds / 3600000);
}
public static long getMinutes(long totalSeconds) {
return (long) Math.floor((totalSeconds - 3600000 * getHours(totalSeconds)) / 60000);
}
public static long getSeconds(long totalSeconds) {
return (long) Math.floor(totalSeconds - 3600000 * getHours(totalSeconds) - 60000 * getMinutes(totalSeconds));
}
public static long getMilliseconds(long totalSeconds) {
return (long) Math.floor(getSeconds(totalSeconds) / 1000);
}
对于 ms,我将秒除以 1000。现在我以 12:34:56.000的格式获得时间。代替毫秒总是.000
怎么了?如何获得毫秒?