1
這是我的代碼顯示應用程序的正常運行時間:ManagementFactory.getRuntimeMXBean()getUptime()格式來顯示日,小時,分鐘和秒
/**
* Gets the uptime of the application since the JVM launch
* @return The uptime in a formatted String (DAYS, MONTHS, MINUTES, SECONDS)
*/
public static String getGameUptime() {
RuntimeMXBean mxBean = ManagementFactory.getRuntimeMXBean();
DateFormat dateFormat = new SimpleDateFormat("dd:HH:mm:ss");
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT+0"));
return dateFormat.format(new Date(mxBean.getUptime()));
}
但是,當應用程序只運行了持續3分50秒,將返回「01:00:03:50」。在這種情況下,01應該是00。這是什麼原因?我該如何解決?