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。这是什么原因?我该如何解决?